Language detection

Permalink
Hi,

I'm making my first 5.7 C5 site, so I'm still a bit lost on the new way of doing things.

I used to use this for redirecting to the current language homepage:
$home = DIR_REL;
if ( Package::getByHandle('multilingual') ) {
    $ms = MultilingualSection::getCurrentSection();
    if (is_object($ms)) {
    $home = Loader::helper('navigation')->getLinkToCollection($ms, true);
    }
}


And this to change things based on language.
$lh = Loader::helper('section', 'multilingual');
$lang = $lh->getLanguage();
if ($lang == "pt_PT"){
// Do stuff in PT
} else {
// Do stuff not in PT
}


How can I go and to these things in 5.7?

Thank you

GBNT
View Replies: View Best Answer
Steevb replied on at Permalink Reply 2 Attachments
Steevb
Try under 'Dashboard' - 'System& Settings' - 'Multilingual' and click 'Multilingual Settings'. I set up my language trees and content sections, then at bottom set up the 'Multilingual Settings'.

See attached.

If you have a link I'll see if works at my end.
mdunbavan replied on at Permalink Reply
Hi Steevb,

Did you create the content areas under the main Home parent item in the sitemap? Like this:

Home -> fr -> en etc etc
Steevb replied on at Permalink Reply 1 Attachment
Steevb
See attached.
mdunbavan replied on at Permalink Reply
oh right okay. That makes much sense now
mlocati replied on at Permalink Best Answer Reply
mlocati
To retrieve the language associated to a page (let's call it $c):
$ms = \Concrete\Core\Multilingual\Page\Section\Section::getBySectionOfSite($c);
if (is_object($ms)) {
   if ($ms->getLocale() === 'pt_PT') {
      echo 'Porto Santo Island is wonderful';
   }
}


If you want work with the current page, replace the first line above with:
$ms = \Concrete\Core\Multilingual\Page\Section\Section::getCurrentSection();
GBNT replied on at Permalink Reply
GBNT
Thank you, exactly what I wanted!