Know what is the language of the current page

Permalink
How to know if the current page is in french or english for instance, in order to display specific things (a flag for instance ...) in the php template ??

 
codingpenguins replied on at Permalink Reply
Not sure how good your php coding is, but the $_SERVER has a list of languages in the order of preference. Below is the code to get the two letter language code that is the 1st priority. Just add a if statement in the php template (I usually do not call files like this, I usually use the reference number, but easy for the example):

if($langCode == 'en') {$flagImg = "/files/1001/2001/3001/americanFlag.jpg"}
else if ($langCode == 'fr') ($flagImg = "/files/1001/2001/3001/franceFlag.jpg"}


$langCode = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);


Let me know if you need more help
PatrickHeck replied on at Permalink Best Answer Reply
PatrickHeck
My understanding of the question is that yukulelix is trying to figure out the language of the currently displayed page and not just the preferred language of the browser.
The code for that would be:
Loader::model('section', 'multilingual');
$lang = MultilingualSection::getCurrentSection()->getLanguage();
codingpenguins replied on at Permalink Reply
I was unaware of this model in internationalization. This is a cleaner solution and will give the same result as the current page. Thanks for informing me about this as well, PatrickHeck.
rubbik replied on at Permalink Reply
You can also find a full Language information (instead of en => en_GB)
Loader::model('section', 'multilingual');
    $lang = strtolower(MultilingualSection::getCurrentSection()->getLocale());