laravel - Laravel5 multilanguage domains -


i have issues laravel5. got multiple domains linked single application, each domain can have multiple languages. locale string should not appear until different language selected domain.

maybe 1 has experience this. etc.:

domain.com/home domain.net domain.lt/pagrindinis domain.lt/en/home 

i found solution:

on app.php made custom array locations:

'domains' => [     'domain_1' => [      'locales' => ['en', 'lt'],      'locale' => 'lt' // default locale domain    ],    'domain_2' => [      'locales' => ['ru', 'en']      'locale' => 'ru',    ],  ]; 

and in route service provider.

/**      * handle app requests      *      * @param router $router      * @param request $request      * @return \illuminate\http\redirectresponse|\illuminate\routing\redirector      */     public function map(router $router, request $request)     {         $locale = $this->getlocalebydomain($request);          $requestlocale = $request->segment(1);          $options = [             'namespace' => $this->namespace         ];          if (in_array($requestlocale, config::get('app.domains')[$request->gethost()]['locales'])) {             $locale = $requestlocale;              $options = array_merge(                 $options,                 [                     'prefix' => $locale                 ]             );         }          app()->setlocale($locale);          $router->group($options, function ($router) {             require app_path('http/routes.php');         });     }      /**      * retrieve locale domain      *      * @param $request      * @return mixed      */     protected function getlocalebydomain($request)     {         $locale = config::get('app.fallback_locale');          if (array_key_exists($request->gethost(), config::get('app.domains'))) {             $locale = config::get('app.domains')[$request->gethost()]['locale'];         }          return $locale;     } 

routes.php file contains:

$router->get(trans('routes.contacts'),     [         'as' => 'contacts',         'uses' => 'pagescontroller@contacts'     ] ); 

so reached multiple domains, multiple languages , pretty nice seo url's every locale. maybe can make other ideas?


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -