snipe-it/app/Providers/SnipeTranslationServiceProvider.php
Brady Wetherington 401e1842ee Fixed pluralization bug due to dashed-locale names instead of underscored
Our locale directories are named things like 'en-US'. But the pluralization
code used by Laravel (through Symfony) requires locale names to be
in the format en_US. This change introduces a new Translator,
SnipeTranslator, which is a tiny set of changes against the built-in
one. It additionally adds a SnipeTranslationServiceProvider, which
loads up the new Translator.
2024-01-26 15:40:55 +00:00

36 lines
1.1 KiB
PHP

<?php
namespace App\Providers;
use App\Services\SnipeTranslator;
use Illuminate\Translation\TranslationServiceProvider;
class SnipeTranslationServiceProvider extends TranslationServiceProvider
{
/**
* Register services.
*
* @return void
*/
public function register()
{
//This is almost an *EXACT* carbon-copy of the TranslationServiceProvider, except with a modified Translator
$this->registerLoader();
$this->app->singleton('translator', function ($app) {
$loader = $app['translation.loader'];
// When registering the translator component, we'll need to set the default
// locale as well as the fallback locale. So, we'll grab the application
// configuration so we can easily get both of these values from there.
$locale = $app['config']['app.locale'];
$trans = new SnipeTranslator($loader, $locale); //the ONLY changed line
$trans->setFallback($app['config']['app.fallback_locale']);
return $trans;
});
}
}