GetSimple Support Forum
PROBLEM PHP - button text translate to 3 languages - Printable Version

+- GetSimple Support Forum (http://get-simple.info/forums)
+-- Forum: GetSimple (http://get-simple.info/forums/forumdisplay.php?fid=3)
+--- Forum: General Questions and Problems (http://get-simple.info/forums/forumdisplay.php?fid=16)
+--- Thread: PROBLEM PHP - button text translate to 3 languages (/showthread.php?tid=6639)



PHP - button text translate to 3 languages - bonyway - 2014-08-12

Hi.
I would like to translate a text for the buttons like “Previous” and “Next” to 3 languages for the news.

I tried to add the script in component (for example for Next):
<?php
if ($lang = 'en') {
echo 'Next';
}else if ($lang = 'de') {
echo 'Naechste';
}else if ($lang = 'fr') {
echo 'Suivant ';
}
?>

In the moment the canonical in german:
<link rel="canonical" href="http://[my domain].de/?lang=de" />
but in a page gets converted in English: “Next”

I’m very bad in PHP
May be someone can me help
Thx

P.S.: the Plugin I18N, I18N Base and I18N_Search working perfect…


RE: PHP - button text translate to 3 languages - Carlos - 2014-08-12

Perhaps with $language instead of $lang ...


RE: PHP - button text translate to 3 languages - bonyway - 2014-08-12

(2014-08-12, 00:56:14)Carlos Wrote: Perhaps with $language instead of $lang ...
already tried it, the same result :-(


RE: PHP - button text translate to 3 languages - Carlos - 2014-08-12

I forgot - If it's in a component, you need to have:

global $language;

before using the variable.


RE: PHP - button text translate to 3 languages - shawn_a - 2014-08-12

heh I added getGobal() to 3.4, cause this drives me nuts sometimes.


RE: PHP - button text translate to 3 languages - bonyway - 2014-08-12

I added in my component “next-page”:
<?php
global $language;
if ($language = 'en') {
echo 'Next';
}else if ($language = 'de') {
echo 'Naechste';
}else if ($language = 'fr') {
echo 'Suivant ';
}
?>
but it still doesn’t work :-(

well, I'll try to describe the details
1.) I have a special page “News” with different functions and variables and one of them is:
<?php
if (function_exists('get_i18n_navigation')) {
get_i18n_component('pagenav');
} else {
get_component('pagenav');
}
?>
2.) The “pagenav” is component, which in turn calls the two components like "next-page" and "prev-page"… so where do I need to add the "global $language;" or "getGobal()"?

@shawn_a
and what you mean with “to 3.4”?

Please guys, I’m not programmer, just a little bit clear, where it should to shove in…. :-)

A lot of thanks in advance!


RE: PHP - button text translate to 3 languages - shawn_a - 2014-08-12

use code tags..

That looks correct where you have it now. At the beginning of your component that uses it.
components are called like functions so imagine they are inside a function ( an anonymous function actually )
That is why the global is needed, because that variable is not in your scope.

It is possible your languages are not defined as 2 letter codes?
you can add a debugLog($language); in there and see

maybe you need a strtolower($language) == 'en'.

Not sure, could be language is not set

PHP Code:
<?php 
global $language;
debugLog($language);
$langlower strtolower($language);
if (
$langlower 'en') { // you might need to make sure this is case sensitive for all these checks
echo 'Next';
}else if (
$langlower 'de') {
echo 
'Naechste';
}else if (
$langlower 'fr') {
echo 
'Suivant ';
}
else echo 
"language not set"// catch if not set to any of these

?>



RE: PHP - button text translate to 3 languages - bonyway - 2014-08-13

Thanks, but still doesn’t work … Confused

Its show the parse error
without "strtolower"
- syntax error, unexpected T_ELSE in /..../admin/inc/theme_functions.php(543) : eval()'d code on line 10 »
and with "strtolower"
- syntax error, unexpected '{' in /..../admin/inc/theme_functions.php(543) : eval()'d code on line 6»
but both with ==
only with one "=" get total error

what do you mean with “defined as 2 letter codes”?
I have some de & en Sites and it working perfect with switching to another language (return_i18n_lang_url).


RE: PHP - button text translate to 3 languages - shawn_a - 2014-08-13

I fixed the code, it was psuedo code, should work now, and turn debug mode on.

I mean en as opposed to en_US


RE: PHP - button text translate to 3 languages - bonyway - 2014-08-13

No Errors, but show only in Englich "Next"

I tried to "en_US" and "de_DE" - does not change anything


RE: PHP - button text translate to 3 languages - bonyway - 2014-08-13

I'm rearranged the variable with places, - displayed only at the first position