I'm using locale/i18n and I can't seem to find which variable or function returns the currently active language (for example 'en', 'nl', 'fr', ..) Could someone point me in the right direction?

Comments

mdixoncm’s picture

wmostrey’s picture

That variable is not even set, so that's not it..

*update*
It's $language ;)

mdixoncm’s picture

I think we are at cross purposes :)

The $locale is the user's locale, which is used by the locale module to determine which translation to use (it is a global variable).

The i18n module uses a static variable $i18n_language to hold the current language of the page in - and a function i18n_get_lang() to get and set the static variable.

There isn't a global $language variable, but each node does have a language property associated with it ....

Like books? Check out booktribes the new (Drupal based) community for book lovers
from Computerminds

wmostrey’s picture

Thanks a lot for the info. It appears there /is/ a $language variable when the url contains the language, for instance example.com/fr then $language is "fr". I don't know if this comes from locale or i18n, but it's there, and only when the url contains the language.

vacilando’s picture

True, even in D6, $language->language is populated only when the language code is in the URL! Without it being in the URL, even translated pages show always 'en' (in my case). Why?

RAWDESK’s picture

This I8n function returns your current (session) language:
i18n_language_context()->language;
The i18n_get_lang() was not present in my actual i18n installed module version.

If you are looking for a solution without using a variable, you can use i18n_taxonomy_localize_terms() function in case taxonomy terms are the subject for localization.
My case summarized in comment of this thread :
https://www.drupal.org/node/951760#comment-9240793