diff options
author | msquare <msquare@notrademark.de> | 2019-10-13 13:03:10 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-10-13 13:03:10 +0200 |
commit | f7bbcfb345c77a2dc89b18854352ee92c8c3cea8 (patch) | |
tree | a3c92b65a57471e075fbc0cea6069da438bd4c58 /src | |
parent | b581da01a3dff2e6e8fbb748050442b22a4af213 (diff) | |
parent | d2e3ce27f0a0e4c36fd12ed451e6c829ba510e49 (diff) |
Merge pull request #655 from MyIgel/ci-build-translation
CI: Build translation files for container and release archive, load .po if .mo not generated
Diffstat (limited to 'src')
-rw-r--r-- | src/Helpers/Translation/TranslationServiceProvider.php | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/src/Helpers/Translation/TranslationServiceProvider.php b/src/Helpers/Translation/TranslationServiceProvider.php index 09337dad..62247000 100644 --- a/src/Helpers/Translation/TranslationServiceProvider.php +++ b/src/Helpers/Translation/TranslationServiceProvider.php @@ -5,6 +5,7 @@ namespace Engelsystem\Helpers\Translation; use Engelsystem\Config\Config; use Engelsystem\Container\ServiceProvider; use Gettext\Translations; +use Illuminate\Support\Str; use Symfony\Component\HttpFoundation\Session\Session; class TranslationServiceProvider extends ServiceProvider @@ -67,14 +68,18 @@ class TranslationServiceProvider extends ServiceProvider public function getTranslator(string $locale): GettextTranslator { if (!isset($this->translators[$locale])) { - $file = $this->app->get('path.lang') . '/' . $locale . '/default.mo'; + $file = $this->getFile($locale); /** @var GettextTranslator $translator */ $translator = $this->app->make(GettextTranslator::class); /** @var Translations $translations */ $translations = $this->app->make(Translations::class); - $translations->addFromMoFile($file); + if (Str::endsWith($file, '.mo')) { + $translations->addFromMoFile($file); + } else { + $translations->addFromPoFile($file); + } $translator->loadTranslations($translations); @@ -83,4 +88,20 @@ class TranslationServiceProvider extends ServiceProvider return $this->translators[$locale]; } + + /** + * @param string $locale + * @return string + */ + protected function getFile(string $locale): string + { + $filepath = $file = $this->app->get('path.lang') . '/' . $locale . '/default'; + $file = $filepath . '.mo'; + + if (!file_exists($file)) { + $file = $filepath . '.po'; + } + + return $file; + } } |