8.4.2 How to get language of default locale?

Permalink
What's the code to get language of the main default locale?
\Localization::activeLanguage();

will give the current locale language. But how do I get the default one, not the active one?

Does the site get translated based on the locale or language?

Thank you.

linuxoid
View Replies:
mlocati replied on at Permalink Reply
mlocati
Do you need it in a controller or in a view file?
linuxoid replied on at Permalink Reply
linuxoid
Both. I have to pass it to controller actions and paths in view.

... unless you know how to use single pages in a multilingual site, and how to use URL::to in this case.
mlocati replied on at Permalink Reply
mlocati
In your controller file you can retrieve the code of the default multilingual section of the site with this code:

$site = $this->app->make('site')->getSite();
$defaultLocale = $site->getDefaultLocale();
$defaultLocaleCode = $defaultLocale->getLocale();


in order to get the default language code in the view, I'd write this in the controller:

$this->set('defaultLocaleCode', $defaultLocaleCode);


so that in the view, you simply have to use $defaultLocaleCode.
linuxoid replied on at Permalink Reply
linuxoid
Michele,

Thank you for that info. But does the site get translated based on the locale or language?

Do you know how single pages and URL::to should be used with multilingual? Or if/else for locales/languages is the only way?
mlocati replied on at Permalink Reply
mlocati
Single pages with translatable strings enclosed in t() calls are translated accordingly to the following rules (in order of precedence, from higher to lower priority):

1. if there's a logged in user, concrete5 uses the language specified in the login page
2. if a user visits a multilingual section of the site then goes to a single page, concrete5 uses the language of that multilingual section
3. concrete5 uses the site default language
linuxoid replied on at Permalink Reply
linuxoid
So if translation is based on the language, not locale, could you please tell me how to get the default language in the controller?
mlocati replied on at Permalink Reply
mlocati
The "Language" concept is just a subset of "Locale", only for making the concept easier we sometimes use "language" instead of "locale".

Translations are always based on locales.
linuxoid replied on at Permalink Reply
linuxoid
But I need the language. 1 English language filter can be used for all English locales: en_US, en_GB, en_AU etc. I need to filter by language, not locale.
mlocati replied on at Permalink Reply 1 Attachment
mlocati
A good IDE (like phpstorm, or Eclipse + PDT +https://mlocati.github.io/concrete5-eclipse-plugin... ) is a great help (in the attached image you can see a screenshot of my IDE).
linuxoid replied on at Permalink Reply
linuxoid
Thanks a lot Michele.

IDE... I've been thinking about Eclipse... but got stuck in kWrite )))