naoray/laravel-localizer

This package is abandoned and no longer maintained. No replacement package was suggested.

Tool to manage multiple language app

Fund package maintenance!
Naoray

Installs: 12

Dependents: 0

Suggesters: 0

Security: 0

Stars: 14

Watchers: 1

Forks: 0

Open Issues: 0

Type:package

v2.0.0 2021-02-03 08:26 UTC

This package is auto-updated.

Last update: 2021-07-01 00:11:18 UTC


README

Software License Tests Total Downloads

Easily detect the language of your user from session, cookie, browser locale or app setting. Change locale with a get request to localizer::setLocale and control which language version the user can see via localizer middleware.

This package is using codezero/laravel-localizer behind the scenes and extends its functionality to include:

  • add Route localizer::setLocale for changing locales
  • add Carbon store to get localized timestamps
  • add Facade to use allowedLocales() method in views

Install

composer require naoray/laravel-localizer

Publish config with php artisan vendor:publish --provider="CodeZero\Localizer\LocalizerServiceProvider" --tag="config"

Usage

Add Supported Locales

Edit supported-locales array of the localizer config to include all allowed locales.

'supported-locales' => ['en', 'de']

Add Carbon Store

Add \Naoray\LaravelLocalizer\Stores\CarbonStore::class to localizerstores to enable the carbon store and sync current locale with carbon locale.

'stores' => [
  CodeZero\Localizer\Stores\SessionStore::class,
  CodeZero\Localizer\Stores\CookieStore::class,
  CodeZero\Localizer\Stores\AppStore::class,
  Naoray\LaravelLocalizer\Stores\CarbonStore::class,
],

Use Localizer in middleware

Add localize middleware to your web route in the RouteServiceProvider

//...
protected function mapWebRoutes()
{
    Route::middleware(['web', 'localize'])
          ->namespace($this->namespace)
          ->group(base_path('routes/web.php'));
}

Or simply add it as a middleware to your route groups.

Add Change Locale routes in view

Add Localizer Facade to app config.

//...
'Localizer' => Naoray\LaravelLocalizer\Facades\LocalizerFacade::class,

In the view you can use allowedLocales() to get all allowed locales in the view.

@foreach (Localizer::allowedLocales() as $locale)
  <a href="{{ route('localizer::setLocale', ['locale' => $locale]) }}">{{ strtoupper($locale)}}</a>
@endforeach

Extend Functionalities

You can add new stores and detectors by implementing the corresponding interface. For more info visit codezero/laravel-localizer

Testing

Run the tests with:

vendor/bin/phpunit

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security-related issues, please email DummyAuthorEmail instead of using the issue tracker.

License

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