]> BookStack Code Mirror - bookstack/blob - app/Providers/TranslationServiceProvider.php
6bf57e02190b766b6f71b52063844b34e12970b4
[bookstack] / app / Providers / TranslationServiceProvider.php
1 <?php
2
3 namespace BookStack\Providers;
4
5 use BookStack\Translation\FileLoader;
6 use BookStack\Translation\MessageSelector;
7 use Illuminate\Translation\TranslationServiceProvider as BaseProvider;
8 use Illuminate\Translation\Translator;
9
10 class TranslationServiceProvider extends BaseProvider
11 {
12     /**
13      * Register the service provider.
14      *
15      * @return void
16      */
17     public function register()
18     {
19         $this->registerLoader();
20
21         // This is a tweak upon Laravel's based translation service registration to allow
22         // usage of a custom MessageSelector class
23         $this->app->singleton('translator', function ($app) {
24             $loader = $app['translation.loader'];
25
26             // When registering the translator component, we'll need to set the default
27             // locale as well as the fallback locale. So, we'll grab the application
28             // configuration so we can easily get both of these values from there.
29             $locale = $app['config']['app.locale'];
30
31             $trans = new Translator($loader, $locale);
32             $trans->setFallback($app['config']['app.fallback_locale']);
33             $trans->setSelector(new MessageSelector());
34
35             return $trans;
36         });
37     }
38
39
40
41     /**
42      * Register the translation line loader.
43      * Overrides the default register action from Laravel so a custom loader can be used.
44      *
45      * @return void
46      */
47     protected function registerLoader()
48     {
49         $this->app->singleton('translation.loader', function ($app) {
50             return new FileLoader($app['files'], $app['path.lang']);
51         });
52     }
53 }