|
|
@ -5,6 +5,7 @@ namespace Engelsystem\Helpers\Translation;
|
|
|
|
use Engelsystem\Config\Config;
|
|
|
|
use Engelsystem\Config\Config;
|
|
|
|
use Engelsystem\Container\ServiceProvider;
|
|
|
|
use Engelsystem\Container\ServiceProvider;
|
|
|
|
use Gettext\Translations;
|
|
|
|
use Gettext\Translations;
|
|
|
|
|
|
|
|
use Illuminate\Support\Str;
|
|
|
|
use Symfony\Component\HttpFoundation\Session\Session;
|
|
|
|
use Symfony\Component\HttpFoundation\Session\Session;
|
|
|
|
|
|
|
|
|
|
|
|
class TranslationServiceProvider extends ServiceProvider
|
|
|
|
class TranslationServiceProvider extends ServiceProvider
|
|
|
@ -69,14 +70,18 @@ class TranslationServiceProvider extends ServiceProvider
|
|
|
|
public function getTranslator(string $locale): GettextTranslator
|
|
|
|
public function getTranslator(string $locale): GettextTranslator
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (!isset($this->translators[$locale])) {
|
|
|
|
if (!isset($this->translators[$locale])) {
|
|
|
|
$file = $this->app->get('path.lang') . '/' . $locale . '/default.mo';
|
|
|
|
$file = $this->getFile($locale);
|
|
|
|
|
|
|
|
|
|
|
|
/** @var GettextTranslator $translator */
|
|
|
|
/** @var GettextTranslator $translator */
|
|
|
|
$translator = $this->app->make(GettextTranslator::class);
|
|
|
|
$translator = $this->app->make(GettextTranslator::class);
|
|
|
|
|
|
|
|
|
|
|
|
/** @var Translations $translations */
|
|
|
|
/** @var Translations $translations */
|
|
|
|
$translations = $this->app->make(Translations::class);
|
|
|
|
$translations = $this->app->make(Translations::class);
|
|
|
|
$translations->addFromMoFile($file);
|
|
|
|
if (Str::endsWith($file, '.mo')) {
|
|
|
|
|
|
|
|
$translations->addFromMoFile($file);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
$translations->addFromPoFile($file);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$translator->loadTranslations($translations);
|
|
|
|
$translator->loadTranslations($translations);
|
|
|
|
|
|
|
|
|
|
|
@ -85,4 +90,20 @@ class TranslationServiceProvider extends ServiceProvider
|
|
|
|
|
|
|
|
|
|
|
|
return $this->translators[$locale];
|
|
|
|
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;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|