mahmoud-birdsol / laravel-language by mahmoud-birdsol

Laravel Route Localization Package
80
0
1
Package Data
Maintainer Username: mahmoud-birdsol
Maintainer Contact: mahmoud@birdsol.com (Mahmoud El-Mokhtar)
Package Create Date: 2017-02-26
Package Last Update: 2017-03-15
Language: PHP
License: MIT
Last Refreshed: 2024-12-22 03:13:48
Package Statistics
Total Downloads: 80
Monthly Downloads: 0
Daily Downloads: 0
Total Stars: 0
Total Watchers: 1
Total Forks: 0
Total Open Issues: 0

Laravel Route Localization Package

This package will help you localize your routes, set the language from the routes and add some nice functionality to it.

Installation

composer require birdsolutions/laravel-language

Service Provider Add the service provider to the config/app.php file

[   
    /*
     * Package Service Providers...
     */
    BirdSolutions\Language\Providers\LanguageServiceProvider::class,
]

Facade

'aliases' => [
    ...
    'Language' => BirdSolutions\Language\Facades\Language::class,
]

Config Publish the configuration file.

    php artisan vendor:publish --provider="BirdSolutions\Language\Providers\LanguageServiceProvider"

Middleware Add the language Middleware to the routeMiddleware array in kernel.php

protected $routeMiddleware = [
       ...
        'language' => \BirdSolutions\Language\Middleware\LanguageMiddleware::class,
    ];

Routes

Route::group([
        'prefix' => \Language::getLocale(),
        'middleware' => 'language'
    ], function () {
        // Add Localized routes here.
    });
    

Change Language Manually

    Route::any('/language', '\BirdSolutions\Language\Controllers\LanguageController@changeLanguage');

It will accept an input of language and set the language to the desired, you can send in get or post inputs.

    <a href='/language?language=en'>English</a>