Detect locales automatically
This commit is contained in:
parent
1d95ba7b57
commit
cb20f4e51d
1 changed files with 10 additions and 9 deletions
|
@ -7,6 +7,7 @@
|
||||||
namespace Alltube;
|
namespace Alltube;
|
||||||
|
|
||||||
use Aura\Session\Segment;
|
use Aura\Session\Segment;
|
||||||
|
use Symfony\Component\Finder\Finder;
|
||||||
use Symfony\Component\Translation\Translator;
|
use Symfony\Component\Translation\Translator;
|
||||||
use Symfony\Component\Translation\Loader\PoFileLoader;
|
use Symfony\Component\Translation\Loader\PoFileLoader;
|
||||||
|
|
||||||
|
@ -15,12 +16,7 @@ use Symfony\Component\Translation\Loader\PoFileLoader;
|
||||||
*/
|
*/
|
||||||
class LocaleManager
|
class LocaleManager
|
||||||
{
|
{
|
||||||
/**
|
private const PATH = __DIR__ . '/../i18n/';
|
||||||
* Supported locales.
|
|
||||||
*
|
|
||||||
* @var string[]
|
|
||||||
*/
|
|
||||||
private $supportedLocales = ['en_US', 'fr_FR', 'zh_CN', 'es_ES', 'pt_BR', 'de_DE', 'ar', 'pl_PL', 'tr_TR'];
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Current locale.
|
* Current locale.
|
||||||
|
@ -75,7 +71,7 @@ class LocaleManager
|
||||||
foreach ($this->getSupportedLocales() as $locale) {
|
foreach ($this->getSupportedLocales() as $locale) {
|
||||||
$this->translator->addResource(
|
$this->translator->addResource(
|
||||||
'gettext',
|
'gettext',
|
||||||
__DIR__ . '/../i18n/' . $locale->getIso15897() . '/LC_MESSAGES/Alltube.po',
|
self::PATH . $locale->getIso15897() . '/LC_MESSAGES/Alltube.po',
|
||||||
$locale->getIso15897()
|
$locale->getIso15897()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -90,8 +86,13 @@ class LocaleManager
|
||||||
{
|
{
|
||||||
$return = [];
|
$return = [];
|
||||||
|
|
||||||
foreach ($this->supportedLocales as $supportedLocale) {
|
$finder = new Finder();
|
||||||
$return[] = new Locale($supportedLocale);
|
$finder->depth(0)
|
||||||
|
->directories()
|
||||||
|
->in(self::PATH);
|
||||||
|
|
||||||
|
foreach ($finder as $file) {
|
||||||
|
$return[] = new Locale($file->getFilename());
|
||||||
}
|
}
|
||||||
|
|
||||||
return $return;
|
return $return;
|
||||||
|
|
Loading…
Reference in a new issue