v1.0 2020-11-08 12:22 UTC

This package is auto-updated.

Last update: 2022-05-16 14:59:56 UTC


Laravel locale is a starting point to build on the laravel translation system.


Installing Jetstream

You may use Composer to install Laravel Locale into your new Laravel project:

composer require nascent-africa/laravel-locale


After installation, add the NascentAfrica\LaravelLocale\Http\Middleware\LocaleMiddleware to web route group in the kernel.php file.

     * The application's route middleware groups.
     * @var array
    protected $middlewareGroups = [
        'web' => [


By default, this package supports en and fr locales, but you can reset this by registering your preferred locale option in your service provider:

namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use NascentAfrica\LaravelLocale\LaravelLocaleFacade;

class AppServiceProvider extends ServiceProvider

     * Bootstrap any application services.
     * @return void
    public function boot()
            'en', 'fr'


This package registers a /locales/{local} to enable you switch locales by simply making a get request passing the local you wish to switch to as a parameter.

<a href="{{ url('/locales/en') }}">{{ __('English') }}</a>


<a href="{{ route('locales', 'en') }}">{{ __('English') }}</a>

Vue helper

This package implements a technique by [Daiyrbek Artelov](Daiyrbek Artelov) in his How to use Laravel translations in JS (vue) files? to enable the use of laravel translation in VueJs files using a nice little __(...) function.

You can set this up with following steps:

  1. Import the module and use it with vue.
import Vue from 'vue'

  1. Add local scripts to your layout blade view.
<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">

            window._locale = '{{ app()->getLocale() }}'
            window._translations = {!! cache('translations') !!}

        <!-- or use the blade component -->
        <x-laravel-locale-scripts />

Now you can use the __(..) function in your vue files like so:

    <div class="card">
        <div class="card-header">{{ __('Example Component') }}</div>
        <div class="card-body">
            {{ __("I'm an example component.") }}

export default {
    mounted() {
        console.log(this.__('Component mounted.'))


Run the tests with:



Laravel Locale is open-sourced software licensed under the MIT license.