laraeast/laravel-locales

The package used to support multi locales in your application.

Installs: 58 869

Dependents: 3

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 0

Open Issues: 0

Type:package

v4.2.1 2025-05-28 07:32 UTC

This package is auto-updated.

Last update: 2025-05-28 07:33:43 UTC


README

Build Status Total Downloads Latest Stable Version License

The package used to support multi locales in your application.

Installation

  1. Install package

    composer require laraeast/laravel-locales
  2. 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,
  3. Configure your custom locales:

    php artisan vendor:publish --tag="locales:config"

Usage

Locales selector dropdown:

<div class="dropdown">
  <a class="btn btn-outline-secondary dropdown-toggle" href="#" role="button" id="languageDropdownMenuLink" data-bs-toggle="dropdown" aria-expanded="false">
    {{ Locales::getSvgFlag(width: 25, height: 25) }}
    <span class="ms-2">{{ Locales::getName() }}</span>
  </a>

  <ul class="dropdown-menu" aria-labelledby="languageDropdownMenuLink">
    @foreach(Locales::get() as $locale)
        <li>
            <a class="dropdown-item" href="{{ url('locale/'. $locale->getCode()) }}">
                {{ $locale->getName() }}
            </a>
        </li>
    @endforeach
  </ul>
</div>

API

Locales::get();
// array of supported locales

Locales::set('en');

Locales::current();
// the current locale instance

Locales::current()->getCode();
// or 
Locales::getCode();
// return : en

Locales::current()->getName();
// or 
Locales::getName();
// return : English

Locales::current()->getName();
// or
Locales::getDir();
// return : ltr

Locales::current()->getSvgFlag();
// or
Locales::getSvgFlag();
// return : svg (html)

Locales::from('en');
// return : \Laraeast\LaravelLocales\Enums\Language::EN

Locales::codes();
// return array of configured languages codes: ['en', 'ar', 'fr'. '...etc']

Locales::names();
// return array of configured languages names: ['English', 'العربية', 'Français'. '...etc']

Locales::flags(width: 30, height: 30);
// return array of configured languages svg flags with width=30 and height=30