fixed alias/reference loading for translation strings

This commit is contained in:
Daniel Klabbers 2017-11-27 10:35:57 +01:00
parent 4c94ad5df4
commit 386416c017
3 changed files with 8 additions and 11 deletions

View File

@ -11,12 +11,13 @@
namespace Flarum\Locale;
use Symfony\Component\Translation\Translator as SymfonyTranslator;
use Illuminate\Contracts\Translation\Translator;
class LocaleManager
{
/**
* @var SymfonyTranslator
* @var Translator
*/
protected $translator;
@ -27,9 +28,9 @@ class LocaleManager
protected $css = [];
/**
* @param SymfonyTranslator $translator
* @param Translator $translator
*/
public function __construct(SymfonyTranslator $translator)
public function __construct(Translator $translator)
{
$this->translator = $translator;
}

View File

@ -16,7 +16,6 @@ use Flarum\Foundation\AbstractServiceProvider;
use Illuminate\Contracts\Events\Dispatcher;
use Illuminate\Contracts\Translation\Translator as TranslatorContract;
use Symfony\Component\Translation\MessageSelector;
use Symfony\Component\Translation\Translator;
use Symfony\Component\Translation\TranslatorInterface;
class LocaleServiceProvider extends AbstractServiceProvider
@ -42,10 +41,8 @@ class LocaleServiceProvider extends AbstractServiceProvider
$this->app->alias(LocaleManager::class, 'flarum.localeManager');
$this->app->singleton('translator', function () {
$defaultLocale = $this->getDefaultLocale();
$translator = new Translator($defaultLocale, new MessageSelector());
$translator->setFallbackLocales([$defaultLocale, 'en']);
$translator = new Translator($this->getDefaultLocale(), new MessageSelector());
$translator->setFallbackLocales(['en']);
$translator->addLoader('prefixed_yaml', new PrefixedYamlFileLoader());
return $translator;
@ -55,7 +52,7 @@ class LocaleServiceProvider extends AbstractServiceProvider
$this->app->alias('translator', TranslatorContract::class);
}
private function getDefaultLocale()
private function getDefaultLocale(): string
{
return $this->app->isInstalled() && $this->app->isUpToDate()
? $this->app->make('flarum.settings')->get('default_locale', 'en')

View File

@ -29,7 +29,6 @@ class Translator extends BaseTranslator implements TranslatorContract
} else {
$this->assertValidLocale($locale);
}
$parse = ! isset($this->catalogues[$locale]);
$catalogue = parent::getCatalogue($locale);