/** * Create a new translator instance. * @param \Illuminate\Translation\LoaderInterface $loader * @param string $locale * @param \Illuminate\Filesystem\Filesystem $files * @return void */ public function __construct(LoaderInterface $loader, $locale, $fallbackLocale, Filesystem $files) { parent::__construct($loader, $locale); parent::setFallback($fallbackLocale); $appLoader = new FileLoader($files, app_path() . '/lang'); $this->appTranslator = new IlluminateTranslator($appLoader, $locale); }
/** * Setup the translator instance. * * @param string $fallbackLocale * @param string $path * @return void */ protected function setupTranslator($fallbackLocale, $path) { $file = new Filesystem(); $loader = new FileLoader($file, $path); $trans = new Translator($loader, $this->container['config']['app.locale']); $trans->setFallback($fallbackLocale); $this->translator = $trans; }
/** * Register any translation services. * * @param \Pimple\Container $container */ public function register(Container $container) { $this->registerLoader($container); $container['translator'] = function () use($container) { $config = $container['config']; $translator = new Translator($container['translation.loader'], $config['app.locale']); $translator->setFallback($config['app.fallback_locale']); return $translator; }; }
/** * Register the service provider. * * @return void */ public function register() { $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 Translator($loader, $locale); $trans->setFallback($app['config']['app.fallback_locale']); return $trans; }); }
/** * Handle the command. * * @param Repository $config * @param Application $application */ public function handle(Repository $config, Application $application) { // First trigger to resolve. $application->make('translator'); /* * Change the lang loader so we can * add a few more necessary override * paths to the API. */ $application->singleton('translation.loader', function ($application) { return new Loader($application['files'], $application['path.lang']); }); /* * Re-bind the translator so we can use * the new loader defined above. */ $application->singleton('translator', function ($application) { $loader = $application->make('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 = $application['config']['app.locale']; $trans = new Translator($loader, $locale); $trans->setFallback($application['config']['app.fallback_locale']); return $trans; }); /* * Set the locale if LOCALE is defined. * * LOCALE is defined first thing in our * HTTP Kernel. Respect it! */ if (defined('LOCALE')) { $application->setLocale(LOCALE); $config->set('app.locale', LOCALE); } // Set our locale namespace. $application->make('translator')->addNamespace('streams', realpath(__DIR__ . '/../../../resources/lang')); }
/** * Set the fallback locale being used. * * @param string $fallback * @return void * @static */ public static function setFallback($fallback) { \Illuminate\Translation\Translator::setFallback($fallback); }
/** * Register all available paths into the laravel system * * @param \Illuminate\Contracts\Foundation\Application $app * @return Directory */ public function registerPaths($app) { // only register if tenant directory exists if ($this->base()) { /* * critical priority, load vendors */ if ($this->vendor() && File::exists($this->vendor() . 'autoload.php')) { File::requireOnce($this->vendor() . 'autoload.php'); } /* * highest priority, load service providers; or possible custom code before any other include from tenant */ if ($this->providers() && File::exists($this->providers())) { File::requireOnce($this->providers()); } /* * mediocre priority, load additional config files */ if ($this->config() && File::isDirectory($this->config())) { foreach (File::allFiles($this->config()) as $path) { $key = File::name($path); $app['config']->set($key, array_merge(require $path, $app['config']->get($key, []))); } } /* * lowest priority load view directory */ if ($this->views() && File::isDirectory($this->views())) { $app['view']->addLocation($this->views()); } // set cache if (File::isDirectory($this->cache())) { $app['config']->set('cache.prefix', "{$app['config']->get('cache.prefix')}-{$this->website->id}"); } // @TODO we really can't use cache yet for application cache // replaces lang directory if ($this->lang() && File::isDirectory($this->lang())) { $path = $this->lang(); $app->bindShared('translation.loader', function ($app) use($path) { return new FileLoader($app['files'], $path); }); $app->bindShared('translator', function ($app) { $translator = new Translator($app['translation.loader'], $app['config']['app.locale']); $translator->setFallback($app['config']['app.fallback_locale']); return $translator; }); } // identify a possible routes.php file if ($this->routes() && File::exists($this->routes())) { File::requireOnce($this->routes()); } } return $this; }
/** * Set the fallback locale being used. * * @param string $fallback * * @return void */ public function setFallback($fallback) { //$this->fallback = $fallback; parent::setFallback($fallback); }
protected function registerLangRepository() { $config = $this->get('config'); if ($config->get('lang.use_wordpress')) { add_action('plugins_loaded', function () use($config) { load_plugin_textdomain($config->get('app.plugin_prefix'), false, $config->get('lang.lang_path')); }); return; } // if $loader = new FileLoader(new Filesystem(), $config->get('lang.lang_path')); $translator = new Translator($loader, get_locale()); $translator->setFallback($config->get('lang.fallback_locale')); $this->instance('lang', $translator); }