Posts: 15
Threads: 5
Joined: Oct 2013
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…
Posts: 3,491
Threads: 106
Joined: Mar 2010
Perhaps with $language instead of $lang ...
Posts: 15
Threads: 5
Joined: Oct 2013
(2014-08-12, 00:56:14)Carlos Wrote: Perhaps with $language instead of $lang ...
already tried it, the same result :-(
Posts: 3,491
Threads: 106
Joined: Mar 2010
I forgot - If it's in a component, you need to have:
global $language;
before using the variable.
Posts: 6,266
Threads: 181
Joined: Sep 2011
heh I added getGobal() to 3.4, cause this drives me nuts sometimes.
Posts: 15
Threads: 5
Joined: Oct 2013
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!
Posts: 6,266
Threads: 181
Joined: Sep 2011
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
?>
Posts: 15
Threads: 5
Joined: Oct 2013
Thanks, but still doesn’t work …
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).
Posts: 6,266
Threads: 181
Joined: Sep 2011
I fixed the code, it was psuedo code, should work now, and turn debug mode on.
I mean en as opposed to en_US
Posts: 15
Threads: 5
Joined: Oct 2013
No Errors, but show only in Englich "Next"
I tried to "en_US" and "de_DE" - does not change anything
Posts: 15
Threads: 5
Joined: Oct 2013
I'm rearranged the variable with places, - displayed only at the first position