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

neurovation.kiwi’s picture

why son't use the function

i18n_get_lang()

cu
kiwi

jisse’s picture

The solution is:

global $language ;
$lang_name = $language->language ;

samchok’s picture

Status: Active » Closed (fixed)

that's what i need. thank you!

nozoku’s picture

Version: 6.x-1.0-beta1 » 6.x-1.x-dev
Category: support » bug
Status: Closed (fixed) » Postponed (maintainer needs more info)

When 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...

nozoku’s picture

Status: Postponed (maintainer needs more info) » Fixed

I 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)

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

anodenymous’s picture

Component: Code » Blocks

Thx

this is what i looking for

Magic Science’s picture

Issue summary: View changes

If you need just language prefix to url u can use
Drupal.settings.pathPrefix