2017 © Pedro Peláez
 

library laravel-language

Multilingual routes and language switcher for laravel 5

image

aayaresko/laravel-language

Multilingual routes and language switcher for laravel 5

  • Thursday, September 29, 2016
  • by aayaresko
  • Repository
  • 1 Watchers
  • 0 Stars
  • 22 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 1 Versions
  • 5 % Grown

The README.md

Laravel language

Multilingual routes and language switcher for laravel 5, (*1)

Installation

The preferred way to install extension is via composer. Check the composer.json for this extension's requirements and dependencies., (*2)

To install, either run, (*3)

$ php composer.phar require aayaresko/laravel-language "*"

or add, (*4)

"aayaresko/laravel-language": "*"

to the require section of your composer.json., (*5)

Configuration

After installing the Socialite library, register the aayaresko\language\ServiceProvider in your config/app.php configuration file:, (*6)

'providers' => [
    // Other service providers...
    aayaresko\language\ServiceProvider::class,
],

Also, add the Language facade to the aliases array in your app configuration file:, (*7)

'Language' => aayaresko\language\LanguageFacade::class,

Usage

Use Language::getLocale() method to add language prefix to your routes:, (*8)

Route::group(['prefix' => Language::getLocale()], function () { 
    Route::get('/home', function () {
        return view('frontend.index');
    })->name('home');
});

Use Language::renderDropdownList() in your view-file to generate language dropdown list (note a exclamation marks):, (*9)

{!! Language::renderDropdownList() !!}

This method takes 'locales' array which specified in you app.config file. It assumes that each 'locale' item key is a language 'code' and value is a 'visible_name'. You can control language item label content via Language::renderDropdownList() $label_template value:, (*10)

{!! Language::renderDropdownList('{visible_name} ({code})') !!}

Label will look like this: 'English (en)' You can add additional items to any 'locale' item value and render that value in Language::renderDropdownList(). For example, if you added 'description' and your app.config looks something like this:, (*11)

'locales' => [
    'en' => [
        'visible_name' => 'English',
        'description' => 'Some simple text'
    ], 
    'ru' => 'Русский',
]

You can render 'description' item:, (*12)

{!! Language::renderDropdownList('{visible_name} ({code}) {description}') !!}

Label will look like this: 'English (en) Some simple text', (*13)

Customization

You can customize html of language dropdown list. Simply run php ./artisan vendor:publish --tag=language and edit dropdown.blade.php template in your resources/views/vendor/language directory., (*14)

The Versions

29/09 2016

dev-master

9999999-dev

Multilingual routes and language switcher for laravel 5

  Sources   Download

MIT

The Requires

 

by Andrey Yaresko

laravel language languages multilingual