2017 © Pedro Peláez
 

library locally

Laravel 5 User Preferred Localization

image

ericlagarda/locally

Laravel 5 User Preferred Localization

  • Wednesday, December 7, 2016
  • by Krato1
  • Repository
  • 1 Watchers
  • 1 Stars
  • 9 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

This is a fork to use removed package. Credits to Mohammed Isa

Laravel 5 User Preferred Localization

This package allows users to set the prefered site localization. Locales are based on ISO 639-1 standard. It automatically switch the site langage to the user preference. All you have to do is install it and set a locale for the user., (*1)

Installation

You can install the package via composer, (*2)

composer require ericlagarda/locally

Then you must configure the service provider by adding this in config/app.php, (*3)

'providers' => [
  ...
  Smartisan\Locally\LocallyServiceProvider::class,
];

Also, add the middleware to web group in Kernel.php, (*4)

'web' => [
            ...
            \Smartisan\Locally\Http\Middlewares\LocallyMiddleware::class
        ],

And you must publish the migrations, (*5)

php artisan vendor:publish --provider="Smartisan\Locally\LocallyServiceProvider" --tag="migrations"

Do not forget to migrate your tables, (*6)

php artisan migrate

Finally, add the package trait in your User model., (*7)

class User
{
    use LocallyTrait;
}

Optionally, you can add a Laravel Facade and alias for it in config/app.php, (*8)

'aliases' => [
  ...
  'Locally'   => \Smartisan\Locally\Facades\Locally::class
];

Usage

Set User Locale

If given language code is not exists, an exception will be thrown., (*9)

$user->setLocale('en');

Get User Prefered Locale

If user local is not set, the system default locale will be returned., (*10)

$user->getLocale(); //en

Remove User Prefered Locale

$user->removeLocale();

Supported Locales

An array of supported locales will be returned by scanning resources/lang folder., (*11)

Locally::getSupportedLocales();

Get Language Code / Name

Two helper functions to get language code or name, (*12)

Locally::getLanguageCodeByName('english'); //en
Locally::getLanguageNameByCode('en'); //English

License

The MIT License (MIT). Please see License File for more information., (*13)

The Versions

07/12 2016

dev-master

9999999-dev

Laravel 5 User Preferred Localization

  Sources   Download

MIT

eloquent localization multilingual translate

07/12 2016

1.0.1

1.0.1.0

Laravel 5 User Preferred Localization

  Sources   Download

MIT

eloquent localization multilingual translate