WEB DEVELOPER SITE
TUTORIALS HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

Laravel - Localization


Laravel - Localization : Limitation highlight of Laravel bolsters distinctive language to be utilized in application. You have to store every one of the strings of various language in a document and these records are put away at resources/views directory.

<?php return [ 'welcome' => 'Welcome to the application' ];

Example

Step 1 − Create 3 documents for dialects — English, French, and German. Spare English record at resources/lang/en/lang.php

<?php 

return [ 

'msg' => 'Laravel Internationalization example.' 

]; 

?>

Step 2 − Save French document at resources/lang/fr/lang.php.

<?php 

return [ 

'msg' => 'Exemple Laravel internationalisation.' 

]; 

?>

Step 3 − Save German document at resources/lang/de/lang.php.

<?php 

return [ 

'msg' => 'Laravel Internationalisierung Beispiel.' 

]; 

?>

Step 4 − Create a controller called LocalizationController by executing the accompanying command.

php craftsman make:controller LocalizationController - plain 

Step 5 − After fruitful execution, you will get the accompanying yield −

LocalizationController

Step 6 − Copy the accompanying code to file

app/Http/Controllers/LocalizationController.php

app/Http/Controllers/LocalizationController.php

<?php 

namespace App\Http\Controllers; 

use Illuminate\Http\Request; 

use App\Http\Requests; 

use App\Http\Controllers\Controller; 

class LocalizationController extends Controller { 

public function index(Request $request,$locale){ 

//set's application's locale 

app()- >setLocale($locale); 

//Gets the interpreted message and shows it 

reverberation trans('lang.msg'); 

} 

}

Step 7 − Add a course for LocalizationController in app/Http/routes.php document. Notice that we are passing {locale} contention after restriction/which we will use to see yield in various language.

app/Http/routes.php

Route::get('localization/{locale}','LocalizationController@index'); 

Step 8 − Now, let us visit the distinctive URLs to see every extraordinary language. Execute the beneath URL to see yield in English language.

http://localhost:8000/limitation/en 

Step 9 − The yield will show up as appeared in the accompanying image.

Laravel Internationalization

Step 10 − Execute the underneath URL to see yield in French language.

http://localhost:8000/limitation/fr