TranslationServiceProvider.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. namespace Illuminate\Translation;
  3. use Illuminate\Contracts\Support\DeferrableProvider;
  4. use Illuminate\Support\ServiceProvider;
  5. class TranslationServiceProvider extends ServiceProvider implements DeferrableProvider
  6. {
  7. /**
  8. * Register the service provider.
  9. *
  10. * @return void
  11. */
  12. public function register()
  13. {
  14. $this->registerLoader();
  15. $this->app->singleton('translator', function ($app) {
  16. $loader = $app['translation.loader'];
  17. // When registering the translator component, we'll need to set the default
  18. // locale as well as the fallback locale. So, we'll grab the application
  19. // configuration so we can easily get both of these values from there.
  20. $locale = $app->getLocale();
  21. $trans = new Translator($loader, $locale);
  22. $trans->setFallback($app->getFallbackLocale());
  23. return $trans;
  24. });
  25. }
  26. /**
  27. * Register the translation line loader.
  28. *
  29. * @return void
  30. */
  31. protected function registerLoader()
  32. {
  33. $this->app->singleton('translation.loader', function ($app) {
  34. return new FileLoader($app['files'], [__DIR__.'/lang', $app['path.lang']]);
  35. });
  36. }
  37. /**
  38. * Get the services provided by the provider.
  39. *
  40. * @return array
  41. */
  42. public function provides()
  43. {
  44. return ['translator', 'translation.loader'];
  45. }
  46. }