Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
PROBLEM PHP - button text translate to 3 languages
#1
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…
Reply
#2
Perhaps with $language instead of $lang ...
Reply
#3
(2014-08-12, 00:56:14)Carlos Wrote: Perhaps with $language instead of $lang ...
already tried it, the same result :-(
Reply
#4
I forgot - If it's in a component, you need to have:

global $language;

before using the variable.
Reply
#5
heh I added getGobal() to 3.4, cause this drives me nuts sometimes.
NEW: SA Admin Toolbar Plugin | View All My Plugins
- Shawn A aka Tablatronix
Reply
#6
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!
Reply
#7
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

?>
NEW: SA Admin Toolbar Plugin | View All My Plugins
- Shawn A aka Tablatronix
Reply
#8
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).
Reply
#9
I fixed the code, it was psuedo code, should work now, and turn debug mode on.

I mean en as opposed to en_US
NEW: SA Admin Toolbar Plugin | View All My Plugins
- Shawn A aka Tablatronix
Reply
#10
No Errors, but show only in Englich "Next"

I tried to "en_US" and "de_DE" - does not change anything
Reply
#11
I'm rearranged the variable with places, - displayed only at the first position
Reply




Users browsing this thread: 5 Guest(s)