vendredi 28 octobre 2016

Multilingual ui using Laravel 5.3

i'm working on a CRM that should work on different countries

this is my first time using Laravel so i'm bit confused

my database looks like this:

Language

  • id
  • name
  • short_name (en,ru etc)

Dictionary

  • id
  • label (sign_in,forgot_password etc)
  • value ('Sign In','Вход' etc )
  • language_id

i thought about working this way:

http://domain.com/en

http://domain.com/ru

http://ift.tt/2fnMdnf

http://ift.tt/2dU79N9

if user go to http://domain.com so it will redirect him by this steps:

  1. if the user logged in the past and has cookie with his language
  2. if there is no cookie get the country of the user by his IP
  3. if the country's language is not recognized in the Languages table redirect the user to default language that set on the config/app.php => 'locale' => 'default language'

i wonder if there is any way to do that without sending the language variable in every function in the controllers, what do i mean?

i mean that i dont wont my routes and my controllers to look like this:

Routes

Route::get('/{locale}', 'Auth\LoginController@showLoginForm');  
Route::get('/{locale}/users/', 'UsersController@index');
Route::get('/{locale}/users/view/{id}', 'UsersController@viewUser');

Controllers

public function showLoginForm($locale)
{
    App::setLocale($locale);
    return view('auth.login');
}
...
public function index($locale)
{
    App::setLocale($locale);
    return view('users.index');
}
...

i want it to work in the background without me setting the language every time and setting the routes,

thank you!



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire