I want to put this type of logic in the code of a link for language switching in a multilingual site :

=========================================
If ($CurrentLanguage == "English")
{
switch to French menu, French theme and French content;
switch the switching link to "English";
}
Else if ($CurrentLanguage == "French")
{
switch to English menu, English theme and English content;
switch the switching link to "French";
}
End if
=========================================

When the user clicks on the switching link somewhere on the site (for example in the navigation bar of the header of a custom theme), the above code and logic are executed. I would like to put this code in the page.tpl.php of the custom theme.

I am using the localizer module. The localizer module has a nice switching block for executing this code, but I want to take this code out of the block and put it in a link in the page.tpl.php instead.

Any ideas on how to code this ?
What is the global variable for checking the current language ?

Any suggestions are appreciated. Thanks.

Comments

pearcec’s picture

You could have two separate menus for each locale. Use the Localizer block module to set the menu block to the proper locale.

bluepal’s picture

I have created a menu for each locale, one English menu and one French menu. There is no problem at all in using the localizer block (included in the module) to switch the menu block.

My original question is how to do the same thing ON A LINK ?! Clicking on the link would switch the locale.

How to put the same logic and code of the localizer block in a PHP code for a LINK that I can put anywhere on my site ?

Susggestions anyone ?

nmakarov’s picture

It must be really simple... So how to switch a locale? Function call? Variable?

tille’s picture

..the localizer.block somehow does not do its job - so both of my navi-menues (german/english) are shown..
Now I'd like to fix that and some other issues (different logo-picture for each language etc) through a language-variable - something like

if($language == "English") {
echo("this is english");
return(TRUE);
} else {
echo("this is NOT english");
return(FALSE);
}

..would be phantastic - but I just cant find the appropriate variable that contains the current language.. - ..help..?

thanx! greetz, till..

___________________________

tille’s picture

I posted the question over at the translation-forum - and got the answer to the problem from pobster:

global $locale;
print $locale;

..so for my/our little problem the thing would be something like this:

global $locale;
if($locale=="en") {
return(TRUE);
} else {
return(FALSE);
}

..works with localizer module on, but probably also only with the locale module..

greetz, till..

___________________________
my pictures: www.bilderbook.org

___________________________

flakerimi’s picture

I'm using this:

<?php
$languages=localizer_block_switchuilocale_links(variable_get('localizer_switchblock_showflags', TRUE), variable_get('localizer_switchblock_showlangname',TRUE), variable_get('localizer_switchblock_flagseparator', ' ', FALSE));

foreach($languages as $i=>$link) {
  echo $link . ' | ';
}
?>

_________________________________
mine of creativity

Riccardo83’s picture

I tried to cpy this into my blog and now my whole page is screwed up....

I get this error

Fatal error: Call to undefined function localizer_block_switchuilocale_links() in /home/riccardo/domains/alizee-fanpage.com/includes/common.inc(1450) : eval()'d code on line 2

Check out my blog
http://blog.riccardo-ulpts.com

flakerimi’s picture

Duplicated, my internet network did this :P
_________________________________
mine of creativity

hrmes’s picture

Thus I'd like to use an image as a link for the language switcher, I wanted to ask, how to generate a link to switch from one language to another... so, that the path of the link alternates corresponding to the current language. I was looking through the localizer.module and functions like localizer_switchuilocale($_locale) or localizer_set_uilocale($_locale = '') are sounding quite promising, but apparently and unfortunaltely it doesn't work that easy. Maybe I'm doing sth wrong, thus my php-knowledge is limited, but does anybody has a clue, what I'm doing wrong? Help would be very much appreciated thus I don't know, what else to try...
Thanks very much!

hrmes’s picture

oh ... duplicated post

Archana Shukla’s picture

If you are using i18n module, then it will help...

$current_lang = i18n_get_lang();