Files
Phraseanet/lib/Alchemy/Phrasea/Core/Provider/LocaleServiceProvider.php
Nicolas Le Goff ed3ffb59a6 Merge remote-tracking branch 'upstream/master' into 20150306-elastic-indexer
Conflicts:
	bin/console
	bower.json
	composer.json
	composer.lock
	lib/Alchemy/Phrasea/Application.php
	lib/Alchemy/Phrasea/Border/Manager.php
	lib/Alchemy/Phrasea/Controller/Api/V1.php
	lib/Alchemy/Phrasea/Core/PhraseaEvents.php
	lib/Alchemy/Phrasea/SearchEngine/SearchEngineOptions.php
	lib/classes/caption/field.php
	lib/classes/record/Interface.php
	templates/web/prod/index.html.twig
	www/skins/prod/000000/prodcolor.css
2015-03-10 14:36:31 +01:00

61 lines
1.8 KiB
PHP

<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2015 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Alchemy\Phrasea\Core\Provider;
use Alchemy\Phrasea\Application as PhraseaApplication;
use Silex\Application;
use Silex\ServiceProviderInterface;
class LocaleServiceProvider implements ServiceProviderInterface
{
public function register(Application $app)
{
$app['locale'] = $app->share(function (Application $app) {
if (!$app['configuration.store']->isSetup()) {
return 'en';
}
return $app['conf']->get(['languages', 'default'], 'en');
});
$app['locales.available'] = $app->share(function (Application $app) {
$availableLanguages = PhraseaApplication::getAvailableLanguages();
if ($app['configuration.store']->isSetup() && 0 < count((array) $app['conf']->get(['languages', 'available']))) {
$languages = $app['conf']->get(['languages', 'available']);
$enabledLanguages = $availableLanguages;
foreach ($enabledLanguages as $code => $language) {
if (in_array($code, $languages)) {
continue;
}
unset($enabledLanguages[$code]);
}
if (0 === count($enabledLanguages)) {
$app['monolog']->error('Wrong language configuration, no language activated');
return $availableLanguages;
}
return $enabledLanguages;
}
return $availableLanguages;
});
}
public function boot(Application $app)
{
}
}