Thứ Hai, 5 tháng 9, 2016

Laravel 5 Tutorial : How to Create localization for Multiple languages in laravel 5.3


Laravel 5 Tutorials - in Laravel PHP Framework Localization used for handle multiple languages on your laravel apps. Default installations in Laravel 5.3 is stored on resources\lang\ folders. In previews lessons, we have learn about Authentication Login & Registration Form + Bootstrap in laravel 5.3 and Adding Bootstrap Theme to Laravel 5.3.

In this lessons, we will create simple page that use two different languages,

First, we will create new Controller and will strode on App\Http\Controllers

Use Artisan command >> php artisan make:controller LanguageController

LanguageController.php

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;

class LanguageController extends Controller
{
    // we will create new method
    public function index(Request $request, $locale){
        // set application Locale
        app()->setlocale($locale);
        // get the translated message and show it
        echo trans('language.message');

    }
}

Create new routes

Web.php

Route::get('{locale}', 'LanguageController@index');


Create files for our language,
at the resources\lang\id\ folder, create new file "language.php"

language.php

<?php
  return [
    'message'=>'Hallo semuanya, nama saya adalah Harison Matondang'    
  ];


at the resources\lang\en\ folder, create new file "language.php"

language.php

<?php
  return [
    'message'=>'hello all, my name is Harison Matondang'
  ];

How to Create localization for Multiple languages in laravel 5.3

Video Tutorial localization in Laravel 5.3


see you next lessons ....

Không có nhận xét nào:

Đăng nhận xét