8.4.2 How to get language of default locale?
Permalink
What's the code to get language of the main default locale?
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.
\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.
Do you need it in a controller or in a view file?
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.
... unless you know how to use single pages in a multilingual site, and how to use URL::to in this case.
In your controller file you can retrieve the code of the default multilingual section of the site with this code:
in order to get the default language code in the view, I'd write this in the controller:
so that in the view, you simply have to use $defaultLocaleCode.
$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.
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?
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?
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
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
So if translation is based on the language, not locale, could you please tell me how to get the default language in the controller?
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.
Translations are always based on locales.
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.
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).
Thanks a lot Michele.
IDE... I've been thinking about Eclipse... but got stuck in kWrite )))
IDE... I've been thinking about Eclipse... but got stuck in kWrite )))