2017 © Pedro Peláez
 

translations localizer

Pakcage to change easily default locale in laravel 5.4

image

aitor24/localizer

Pakcage to change easily default locale in laravel 5.4

  • Thursday, December 21, 2017
  • by 24aitor
  • Repository
  • 2 Watchers
  • 17 Stars
  • 1,569 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 36 Versions
  • 6 % Grown

The README.md

, (*1)

Localizer

StyleCI Version Scrutinizer Downloads License , (*2)

What is Localizer?

Localizer is a laravel package to change easily locale on laravel projects., (*3)

It's so simple to use, once it's installed, your App locale will change only by passing routes into localizer middleare., (*4)

Top features:, (*5)

  • Change automatically app locale depending on user browser configuration
  • Get language like 'Spanish' or 'English' from codes such as 'es' or 'en'.
  • Store on users database table the user locale preference
  • Restrict users to set languages you don't have translations

Getting Started

1. Install it with composer

Running the command below:, (*6)

composer require aitor24/localizer

2. Register service provider

Register the localizer service provider on config/app.php., (*7)

Aitor24\Localizer\LocalizerServiceProvider::class,

Remind to add alias to use Localizer functions comfortably., (*8)

'Localizer'   => Aitor24\Localizer\Facades\LocalizerFacade::class,

3. Publish config

It will publish config file., (*9)

Running the command below:, (*10)

php artisan vendor:publish --tag=localizer_config

3.1 Publish languages

Also you can publish your languages to modify or add., (*11)

php artisan vendor:publish --tag=localizer_languages

4. Migrate

Publish migrations:, (*12)

php artisan vendor:publish --tag=localizer_migrations

Running the command below:, (*13)

php artisan migrate

5. Configure defalt values

Default values can be modified also on config/localizer.php., (*14)

Keys

  • routes: Makes routes available.
  • carbon: Sets carbon translator language.
  • homeRoute: Make home route available.
  • set_auto_lang: Sets language automatically depending on user's browser config
  • default_lang: Default language if set_auto_lang is false or user is attempting to set an unallowed language
  • prefix: Prefix of routes URI to set locale,
  • allowed_langs: All allowed languages,
  • middleware: default middleware to set locale,

Using Localizer

Middleware

All routes in which you want to set language should be under the localizer's middleware to set at each request de App locale., (*15)

Route::group(['middleware' => 'localizer'], function () {

    // Here your routes

});

Changing languages

  • Via URL with return home: /lang/set/{locale}/home
  • Via URL with return back: /lang/set/{locale}

Tip: /lang prefix will be changed on config, (*16)

Example languages view

Following there are a little code snippet of a view to select and set languages:, (*17)

@foreach (Localizer::allowedLanguages() as $code => $value)
    <a href="{{ Localizer::setRouteHome($code) }}">{{ $value }}</a>
@endforeach

API

Localizer::allowedLanguages()

Returns an array with [$code => $language] for all allowed languages of config., (*18)

Localizer::addNames($codes)

Get an array like [$code => $language] from an array of only $codes., (*19)

Localizer::addCodes($lang)

Get an array like [$language => $code] from an array of only $langs., (*20)

Localizer::setRoute($code)

Used for modals or dropdowns, (*21)

Returns the url to set up language and return back., (*22)

Also if you prefer to use directly route() function you can use it as following code:, (*23)

{{ route('localizer::setLocale', ['locale' => $code]) }}

Localizer::setRouteHome($code)

Used for language selection views, (*24)

Returns the url to set language and return '/' url('/'), (*25)

Also if you prefer to use directly route() function you can use it as following code:, (*26)

{{ route('localizer::setLocaleHome', ['locale' => $code]) }}

Localizer::getLanguage($code = App::getLocale())

Returns the language name of $code if specified or the current language setted if not., (*27)

Tip: Use App::getLocale() to get the current locale, (*28)

The Versions

21/12 2017

dev-master

9999999-dev

Pakcage to change easily default locale in laravel 5.4

  Sources   Download

MIT

The Requires

 

21/12 2017

dev-analysis-8AxA6l

dev-analysis-8AxA6l

Pakcage to change easily default locale in laravel 5.4

  Sources   Download

MIT

The Requires

 

14/12 2017

1.4.6

1.4.6.0

Pakcage to change easily default locale in laravel 5.4

  Sources   Download

MIT

The Requires

 

14/12 2017

1.4.5

1.4.5.0

Pakcage to change easily default locale in laravel 5.4

  Sources   Download

MIT

The Requires

 

14/12 2017

dev-patch-1

dev-patch-1

Pakcage to change easily default locale in laravel 5.4

  Sources   Download

MIT

The Requires

 

14/11 2017

1.4.4

1.4.4.0

Pakcage to change easily default locale in laravel 5.4

  Sources   Download

MIT

The Requires

 

14/11 2017

dev-analysis-zedNOa

dev-analysis-zedNOa

Pakcage to change easily default locale in laravel 5.4

  Sources   Download

MIT

The Requires

 

14/11 2017

dev-analysis-8LRGZm

dev-analysis-8LRGZm

Pakcage to change easily default locale in laravel 5.4

  Sources   Download

MIT

The Requires

 

08/11 2017

1.4.3

1.4.3.0

Pakcage to change easily default locale in laravel 5.4

  Sources   Download

MIT

The Requires

 

17/09 2017

1.4.2

1.4.2.0

Pakcage to change easily default locale in laravel 5.4

  Sources   Download

MIT

The Requires

 

28/05 2017

1.4.1

1.4.1.0

Pakcage to change easily default locale in laravel 5.4

  Sources   Download

MIT

The Requires

 

27/05 2017

1.4

1.4.0.0

Pakcage to change easily default locale in laravel 5.4

  Sources   Download

MIT

The Requires

 

27/05 2017

dev-analysis-zYBryK

dev-analysis-zYBryK

Pakcage to change easily default locale in laravel 5.4

  Sources   Download

MIT

The Requires

 

26/05 2017

1.3.12

1.3.12.0

Pakcage to change easily default locale in laravel 5.4

  Sources   Download

MIT

The Requires

 

09/05 2017

1.3.11

1.3.11.0

Pakcage to change easily default locale in laravel 5.4

  Sources   Download

MIT

The Requires

 

07/05 2017

1.3.10

1.3.10.0

Pakcage to change easily default locale in laravel 5.4

  Sources   Download

MIT

The Requires

 

06/05 2017

1.3.9

1.3.9.0

Pakcage to change easily default locale in laravel 5.4

  Sources   Download

MIT

The Requires

 

06/05 2017

dev-analysis-8PrWoL

dev-analysis-8PrWoL

Pakcage to change easily default locale in laravel 5.4

  Sources   Download

MIT

The Requires

 

06/05 2017

1.3.8

1.3.8.0

Pakcage to change easily default locale in laravel 5.4

  Sources   Download

MIT

The Requires

 

05/05 2017

1.3.7

1.3.7.0

Pakcage to change easily default locale in laravel 5.4

  Sources   Download

MIT

The Requires

 

05/05 2017

1.3.6

1.3.6.0

Pakcage to change easily default locale in laravel 5.4

  Sources   Download

MIT

The Requires

 

05/05 2017

1.3.5

1.3.5.0

Pakcage to change easily default locale in laravel 5.4

  Sources   Download

MIT

The Requires

 

20/04 2017

1.3.4

1.3.4.0

Pakcage to change easily default locale in laravel 5.4

  Sources   Download

MIT

The Requires

 

19/04 2017

1.3.3

1.3.3.0

Pakcage to change easily default locale in laravel 5.X

  Sources   Download

MIT

The Requires

 

18/04 2017

1.3.2

1.3.2.0

Pakcage to change easily default locale in laravel 5.X

  Sources   Download

MIT

The Requires

 

17/04 2017

1.3.1

1.3.1.0

Pakcage to change easily default locale in laravel 5.X

  Sources   Download

MIT

The Requires

 

16/04 2017

1.3.0

1.3.0.0

Pakcage to change easily default locale in laravel 5.X

  Sources   Download

MIT

The Requires

 

31/01 2017

1.2

1.2.0.0

Pakcage to change easily default locale in laravel 5.X

  Sources   Download

MIT

The Requires

 

19/12 2016

1.1.2

1.1.2.0

Pakcage to change easily default locale in laravel 5.X

  Sources   Download

MIT

The Requires

 

19/12 2016

1.1.1

1.1.1.0

Pakcage to change easily default locale in laravel 5.X

  Sources   Download

MIT

The Requires

 

14/12 2016

dev-analysis-86nbB9

dev-analysis-86nbB9

Pakcage to change easily default locale in laravel 5.X

  Sources   Download

MIT

The Requires

 

14/12 2016

1.1

1.1.0.0

Pakcage to change easily default locale in laravel 5.X

  Sources   Download

MIT

The Requires

 

08/12 2016

1.0.1

1.0.1.0

Pakcage to change easily default locale in laravel 5.X

  Sources   Download

MIT

The Requires

 

07/12 2016

1.0

1.0.0.0

Pakcage to change easily default locale in laravel 5.X

  Sources   Download

MIT

The Requires

 

07/12 2016

dev-analysis-8P5Q1e

dev-analysis-8P5Q1e

Pakcage to change easily default locale in laravel 5.X

  Sources   Download

MIT

The Requires

 

03/12 2016

dev-analysis-qv027N

dev-analysis-qv027N

Pakcage to change easily default locale in laravel 5.X

  Sources   Download

MIT

The Requires