TranslationServiceProvider.php 1.5KB

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