Create folders inside resources/lang for different different languages and write message files with same name and also write same key among all the message files.
like I have 2 languages ENĀ and ES.. then I created 2 folders, one is en and second is es.
Inside both folders I created password files. like:
en/passwords.php
1 2 3 4 5 6 |
<?php return [ 'type' =>'en' ]; |
es/passwords.php
1 2 3 4 5 6 |
<?php return [ 'type' =>'es' ]; |
Now I can call any of these 2 language messages by their file and key name like:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
<?php namespace App\Http\Controllers; use App\Http\Controllers\Controller; class UserController extends Controller { public function __construct() { \App::setLocale('es'); // \App::setLocale('en'); } public function index() { $message = trans('passwords.type'); return view('welcome',['message'=>$message]); } } |
here I can pass the language code dynamically in the constructor and message of that language will be called. ...