diff options
author | Igor Scheller <igor.scheller@igorshp.de> | 2019-10-09 13:54:04 +0200 |
---|---|---|
committer | msquare <msquare@notrademark.de> | 2019-10-13 13:16:22 +0200 |
commit | fa35187795734ad4f4dc33f74cc0fe020dd9ff32 (patch) | |
tree | 03ca408a01ce790e73d7b4453bdd5e50c5d6a73b /src | |
parent | 973c108b153fb1d8be3576935c58e92865d19e7a (diff) |
Removed .mo translation files from version control, use .po as fallback
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 05e782ec..6df9b0fe 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 @@ -69,14 +70,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); @@ -85,4 +90,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; + } } |