laraeast / laravel-locales
The package used to support multi locales in your application.
Installs: 54 627
Dependents: 3
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Type:package
Requires
- laravel/framework: >=5.5
Requires (Dev)
- mockery/mockery: ^1.4
- orchestra/testbench: ~3.0|~4.0|~5.0|~6.0
README
The package used to support multi locales in your application.
Installation
-
Install package
composer require laraeast/laravel-locales
-
Edit config/app.php (Skip this step if you are using laravel 5.5+)
service provider:
Laraeast\LaravelLocales\Providers\LocalesServiceProvider::class,
class aliases:
'Locales' => Laraeast\LaravelLocales\Facades\Locales::class,
-
Configure your custom locales:
php artisan vendor:publish --tag="locales:config"
-
Copy locales flags to public:
php artisan vendor:publish --tag="locales:flags"
Usage
Locales selector dropdown:
<li class="dropdown"> <a href="#" class="dropdown-toggle" data-toggle="dropdown"> <img src="{{ Locales::getFlag() }}"> {{ Locales::getName() }} </a> <ul class="dropdown-menu"> @foreach(Locales::get() as $locale) <li> <a href="{{ url('locale/'. $locale->code) }}"> {{ $locale->name }} </a> </li> @endforeach </ul> </li>
API
Locales::get(); // array of supported locales Locales::set('en'); Locales::current(); // the current locale instance Locales::current()->code; // or Locales::getCode(); // return : en Locales::current()->name; // or Locales::getName(); // return : English Locales::current()->dir; // or Locales::getDir(); // return : ltr Locales::current()->flag; // or Locales::getFlag(); // return : /images/flags/us.png