From 6cde313e47cd08216ff15d733c8de894f2657a8b Mon Sep 17 00:00:00 2001 From: Luca Date: Fri, 25 Oct 2019 09:33:09 +0200 Subject: Move translations whose message ids do not appear as literals in the sources into a separate file Test whether additional.{m,p}o files are loaded correctly --- src/Helpers/Translation/TranslationServiceProvider.php | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'src/Helpers') diff --git a/src/Helpers/Translation/TranslationServiceProvider.php b/src/Helpers/Translation/TranslationServiceProvider.php index 6df9b0fe..5534a1c3 100644 --- a/src/Helpers/Translation/TranslationServiceProvider.php +++ b/src/Helpers/Translation/TranslationServiceProvider.php @@ -70,17 +70,20 @@ class TranslationServiceProvider extends ServiceProvider public function getTranslator(string $locale): GettextTranslator { if (!isset($this->translators[$locale])) { - $file = $this->getFile($locale); + $names = ['default', 'additional']; /** @var GettextTranslator $translator */ $translator = $this->app->make(GettextTranslator::class); /** @var Translations $translations */ $translations = $this->app->make(Translations::class); - if (Str::endsWith($file, '.mo')) { - $translations->addFromMoFile($file); - } else { - $translations->addFromPoFile($file); + foreach ($names as $name) { + $file = $this->getFile($locale, $name); + if (Str::endsWith($file, '.mo')) { + $translations->addFromMoFile($file); + } else { + $translations->addFromPoFile($file); + } } $translator->loadTranslations($translations); @@ -93,11 +96,12 @@ class TranslationServiceProvider extends ServiceProvider /** * @param string $locale + * @param string $name * @return string */ - protected function getFile(string $locale): string + protected function getFile(string $locale, string $name = 'default'): string { - $filepath = $file = $this->app->get('path.lang') . '/' . $locale . '/default'; + $filepath = $file = $this->app->get('path.lang') . '/' . $locale . '/' . $name; $file = $filepath . '.mo'; if (!file_exists($file)) { -- cgit v1.2.3-54-g00ecf