Skip to content

The package introduces dynamic language change capability for a laravel instance.

License

Notifications You must be signed in to change notification settings

danieldoinov/laravel-language-integration

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Laravel Language Integration

Latest Version on Packagist Software License Build Status Coverage Status Quality Score Total Downloads

Provides functionality to dynamically change a Laravel current locale. Basically makes laravel multilingial from a users stand point.

Install

Via Composer

$ composer require danieldoinov/languageintegration

This package has integrated geo-location that uses the following package

Stevebauman\Location

It should be installed automatically with this one but just in case that it isn't you can install it by running

composer require stevebauman/location

You must add the providers in config/app.php

Stevebauman\Location\LocationServiceProvider::class,
DanielDoinov\LanguageIntegration\LanguageIntegrationServiceProvider::class

You can then publish the configuration files.

php artisan vendor:publish --provider="danieldoinov\LanguageIntegration\LanguageIntegrationProvider"
php artisan vendor:publish --provider="Stevebauman\Location\LocationServiceProvider"

Usage

What the package does is add one route and one middleware that handle the locale change. out of the box it will give you the following options for changing the locale:

http://yourdomain.com/locale/[lang]

Linking to that url will change the applications locale to the one that you specified. The [lang] variable must a valid locale code and must be present in the config/languages.php configuration file. After the change of locale the route will redirect back with any other input present.

You can create links that change the locale dynamically my adding a ?lang=[lang] to any route in you application.

The first time the application starts the middleware will look for a cookie with a preferred locale. If none is found it will geo-locate the user and switch to the configured locale based on country code.

You can configure all of that from config/languages.php as well as cookie name and route format.

Here is the default full configuration:

    'cookie_key' => 'current_locale',     
    'locale' => [
        'en' => 'English',
        'de' => 'Deutsche',
        'es' => 'Español',
        'ru' => 'Русский'
    ],
    'country_code_to_locale' => [
        'US' => 'en',
        'GB' => 'en',
        'CA' => 'en',
        'UM' => 'en',
         //spanish
        'ES' => 'es',
         //german
        'DE' => 'de',
         //Russion
        'RU' => 'ru',
    ],    
    'route' => '/locale/{lang}',
    'route_name' => 'setLocale'

Hope you like it and helps!

Credits

License

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

About

The package introduces dynamic language change capability for a laravel instance.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages