Test if a site is mutilingual and the languages in use

Permalink
I need to be able to find out in code, if a site is multilingual and what languages are installed.

I'm in the process of developing a package that shows artists work.
In the art world there is a specific convention as to how to show work - each image has to be accompanied by the Date, Media used etc.
The obvious way to accomplish this is using attributes attached to each image. This is fairly easy if the site is only in one language.
However if the site is multilingual, certain attributes, the media used for example, need to have translations.

So in the installation controller, where I am creating the attributes, I need
a) test if the site is multilingual and
b) if it is, get an array of the language codes in use/installed (FR, EN etc)
Then I can create attributes like media_FR, media_EN which can be called according to the context of the page.

All I can find is code to find out the language of a page/section (which is useful in view.php), but in the case of installing a package, there isn't this context.

any help welcome

 
mlocati replied on at Permalink Reply
mlocati
This is a perfect use case where my Multilingual Attributes package (seehttps://www.concrete5.org/marketplace/addons/multilingual-attributes... ) could be useful...

The only problem is that package is for concrete5 5.6 (but in my todo-list I have a note to upgrade it to concrete5 5.7).

I think I'll do this in a few days, but it may require some time before it'll be reviewed in the PRB.

Maybe I can send you a beta version as soon as I write a quite stable version of it...
NickKN replied on at Permalink Reply
To be honest, I tried the add-on and couldn't get on with it. I probably didn't configure it properly and ended up with attribute entries for about 20 languages. Looking at it though, I wonder if I've got the right folder structure.

The public who are likely to use this add on - if I ever get it finished - aren't the sort to want to go looking other add-ons. It more or less has to work out of the box (which means I'll have to create a page type as well - just realised).

I have found this snippet while looking at the API (and understanding about 2%)
if (\Core::make('multilingual/detector')->isEnabled()) {... }

It looks as though it might do the trick. Then I suppose a database request to get the locales if true.
I'm having to learn more than I want to...
mlocati replied on at Permalink Reply
mlocati
To be honest, I tried the add-on and couldn't get on with it.
I probably didn't configure it properly and ended up with attribute entries for about 20 languages.
Looking at it though, I wonder if I've got the right folder structure.


That's probably because you didn't have a multilingual website, so my addon falls-back to using all the available locales of concrete5.
BTW, changing this behaviour should be quite easy: in the new Multilingual Attributes addon for 5.7 there'll be an option to control if the attribute should use all the core translations if multilingual is not enabled.

About determining the languages of a multilingual websites:
if (\Core::make('multilingual/detector')->isEnabled()) {
    $activeLocale = \Localization::activeLocale();
    foreach (Concrete\Core\Multilingual\Page\Section\Section::getList() as $multilingualSection) {
                $availableLanguageCode = $multilingualSection->getLocale();
                $availableLanguageName = \Localization::getLanguageDescription($availableLanguageCode, $activeLocale);
            }
    }
}