Hi,
how can I get the current language selected by the user?
I mean, when the user clicks on "english" in the language box, in a php script I need to know which is the language choosen by the user, in this case "english". How is it possible?
Thank you!
Comments
Comment #1
neurovation.kiwi commentedwhy son't use the function
i18n_get_lang()
cu
kiwi
Comment #2
jisse commentedThe solution is:
global $language ;
$lang_name = $language->language ;
Comment #3
samchok commentedthat's what i need. thank you!
Comment #4
nozoku commentedWhen I use this code in a tempate (node.tpl):
global $language ;
$lang_name = $language->language ;
I'm getting an error:
warning: Attempt to assign property of non-object in /includes/theme.inc on line 1805.
the 1805 line of theme.inc is:
1804 $variables['language'] = $GLOBALS['language'];
1805 $variables['language']->dir = $GLOBALS['language']->direction ? 'rtl' : 'ltr';
1806 $variables['logo'] = theme_get_setting('logo');
I tried to change the code but I'm not good at PHP...
Comment #5
nozoku commentedI just put a function in theme's template.php that is doing the above code and returning the language name - that way I am not getting any errors.
The function:
function UI_lang() {
global $language;
return $language->name;
}
(I used $language->name and I'm getting whole name of the language)
Comment #7
anodenymous commentedThx
this is what i looking for
Comment #8
Magic Science commentedIf you need just language prefix to url u can use
Drupal.settings.pathPrefix