2017 © Pedro Peláez
 

library linguist

Easy localization for the Laravel framework

image

keevitaja/linguist

Easy localization for the Laravel framework

  • Tuesday, July 3, 2018
  • by keevitaja
  • Repository
  • 10 Watchers
  • 177 Stars
  • 4,795 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 14 Forks
  • 1 Open issues
  • 21 Versions
  • 9 % Grown

The README.md

Linguist - Multilingual urls and redirects for Laravel

This package provides an easy multilingual urls and redirection support for the Laravel framework., (*1)

In short Laravel will generate localized urls for links and redirections., (*2)

route('people') 
http://site.com/people
http://site.com/fr/people

Linguist works perfectly well with https://github.com/tightenco/ziggy named Laravel routes for javascript package!, (*3)

Installation

Linguist is very easy to use. The locale slug is removed from the REQUEST_URI leaving the developer with the cleanest multilingual environment possible., (*4)

Install using Composer:, (*5)

composer require keevitaja/linguist

There are several options to make Linguist work., (*6)

Option 1: Modify the public/index.php

Add following line after the vendor autoloading to your projects public/index.php file., (*7)

(new Keevitaja\Linguist\UriFixer)->fixit();

End result would be this:, (*8)

/*
|--------------------------------------------------------------------------
| Register The Auto Loader
|--------------------------------------------------------------------------
|
| Composer provides a convenient, automatically generated class loader for
| our application. We just need to utilize it! We'll simply require it
| into the script here so that we don't have to worry about manual
| loading any of our classes later on. It feels great to relax.
|
*/

require __DIR__.'/../vendor/autoload.php';

(new Keevitaja\Linguist\UriFixer)->fixit();

Option 2: Use LocalizedKernel

Note: This option works only if you have not changed your applications root namespace. Default is App., (*9)

In your projects bootstrap/app.php swap the App\Http\Kernel with Keevitaja\Linguist\LocalazedKernel:, (*10)

/*
|--------------------------------------------------------------------------
| Bind Important Interfaces
|--------------------------------------------------------------------------
|
| Next, we need to bind some important interfaces into the container so
| we will be able to resolve them when needed. The kernels serve the
| incoming requests to this application from both the web and CLI.
|
*/

$app->singleton(
    Illuminate\Contracts\Http\Kernel::class,
    //App\Http\Kernel::class
    Keevitaja\Linguist\LocalizedKernel::class
);

Option 3: modify the App\Http\Kernel

Note: This also works with custom root namespace., (*11)

<?php

namespace App\Http;

use Illuminate\Contracts\Foundation\Application;
use Illuminate\Foundation\Http\Kernel as HttpKernel;
use Illuminate\Routing\Router;
use Keevitaja\Linguist\UriFixer;

class Kernel extends HttpKernel
{

    public function __construct(Application $app, Router $router)
    {
        (new UriFixer)->fixit();

        parent::__construct($app, $router);
    }

Publish config

Finally you need to publish the Linguist config to set your enabled locales and other relavant configurations., (*12)

php artisan vendor:publish --provider="Keevitaja\Linguist\LinguistServiceProvider"

Your personal configuration file will be config/linguist.php., (*13)

Usage

You can add the LocalizeUrls middleware your web middleware group as the first item to get the linguist support:, (*14)

/**
 * The application's route middleware groups.
 *
 * @var array
 */
protected $middlewareGroups = [
    'web' => [
        \Keevitaja\Linguist\LocalizeUrls::class,

Note: This middleware has to be the first item in group!, (*15)

Another option is to use Linguist in your applications service provider:, (*16)

class AppServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot(\Keevitaja\Linguist\Linguist $linguist)
    {
        $linguist->localize();
    }

UrlGenerator will add the locale slug in front of the URI when needed. No extra actions needed., (*17)

Route::get('people', ['as' => 'people.index', 'uses' => ''PeopleController@index'']);
{{ route('people.index') }} or {{ url('people') }}
http://site.com/people // default locale from linguist config
http://site.com/fr/people
http://site.com/ru/people

Switcher is a little helper to get the current URLs for the locale switcher., (*18)

$urls = dispatch_now(new \Keevitaja\Linguist\Switcher);

NB! Both config and route caching are working!, (*19)

Assets

Use linguist helpers for a correct routing of assets, (*20)

Regular Assets, (*21)

twig <link rel="stylesheet" href="{{ linguist_asset('css/style.css') }}"> <script type="text/javascript" src="{{ linguist_asset('js/my_js.js') }}"></script>, (*22)

Secure Assets, (*23)

twig <link rel="stylesheet" href="{{ secure_linguist_asset('css/style.css') }}"> <script type="text/javascript" src="{{ secure_linguist_asset('js/my_js.js') }}"></script>, (*24)

Queues

To make localization work in queues you need to run Linguist->localize($theLocaleYouWant) inside the queued item., (*25)

Licence

MIT, (*26)

The Versions

03/07 2018

dev-master

9999999-dev

Easy localization for the Laravel framework

  Sources   Download

MIT

The Requires

  • php ^7.0

 

The Development Requires

by Tanel Tammik

laravel php i18n localization multilingual

03/07 2018

2.2.2

2.2.2.0

Easy localization for the Laravel framework

  Sources   Download

MIT

The Requires

  • php ^7.0

 

by Tanel Tammik

laravel php i18n localization multilingual

14/11 2017

2.1.2

2.1.2.0

Easy localization for the Laravel framework

  Sources   Download

MIT

The Requires

  • php ^7.0

 

by Tanel Tammik

laravel php i18n localization multilingual

12/11 2017

2.1.1

2.1.1.0

Easy localization for the Laravel framework

  Sources   Download

MIT

The Requires

  • php ^7.0

 

by Tanel Tammik

laravel php i18n localization multilingual

11/11 2017

2.1.0

2.1.0.0

Easy localization for the Laravel framework

  Sources   Download

MIT

The Requires

  • php ^7.0

 

by Tanel Tammik

laravel php i18n localization multilingual

05/11 2017

2.0.3

2.0.3.0

Easy localization for the Laravel framework

  Sources   Download

MIT

The Requires

  • php ^7.0

 

by Tanel Tammik

laravel php i18n localization multilingual

05/11 2017

2.0.1

2.0.1.0

Easy localization for the Laravel framework

  Sources   Download

MIT

The Requires

  • php ^7.0

 

by Tanel Tammik

laravel php i18n localization multilingual

05/11 2017

2.0.0

2.0.0.0

Easy localization for the Laravel framework

  Sources   Download

MIT

The Requires

  • php ^7.0

 

by Tanel Tammik

laravel php i18n localization multilingual

27/10 2017

dev-1/master

dev-1/master

Easy localization for the Laravel framework

  Sources   Download

MIT

The Requires

 

The Development Requires

by Tanel Tammik

laravel php i18n localization multilingual

27/10 2017

1.0.5

1.0.5.0

Easy localization for the Laravel framework

  Sources   Download

MIT

The Requires

 

The Development Requires

by Tanel Tammik

laravel php i18n localization multilingual

11/04 2017

1.0.4

1.0.4.0

Easy localization for the Laravel framework

  Sources   Download

MIT

The Requires

 

The Development Requires

by Tanel Tammik

laravel php i18n localization multilingual

11/04 2017

1.0.2

1.0.2.0

Easy localization for the Laravel framework

  Sources   Download

MIT

The Requires

 

The Development Requires

by Tanel Tammik

laravel php i18n localization multilingual

12/10 2015

1.0.1

1.0.1.0

Easy localization for the Laravel framework

  Sources   Download

MIT

The Requires

 

The Development Requires

by Tanel Tammik

laravel php i18n localization multilingual

14/08 2015

1.0.0

1.0.0.0

Easy localization for the Laravel framework

  Sources   Download

MIT

The Requires

 

The Development Requires

by Tanel Tammik

laravel php i18n localization multilingual

14/08 2015

dev-0/master

dev-0/master

Easy localization for the Laravel framework

  Sources   Download

MIT

The Requires

 

The Development Requires

by Tanel Tammik

laravel php i18n localization multilingual

14/08 2015

0.1.6

0.1.6.0

Easy localization for the Laravel framework

  Sources   Download

MIT

The Requires

 

The Development Requires

by Tanel Tammik

laravel php i18n localization multilingual

26/07 2015

0.1.4

0.1.4.0

Easy localization for the Laravel framework

  Sources   Download

MIT

The Requires

 

The Development Requires

by Tanel Tammik

laravel php i18n localization multilingual

26/07 2015

0.1.3

0.1.3.0

Easy localization for the Laravel framework

  Sources   Download

MIT

The Requires

 

The Development Requires

by Tanel Tammik

laravel php i18n localization multilingual

26/07 2015

0.1.2

0.1.2.0

Easy localization for the Laravel framework

  Sources   Download

MIT

The Requires

 

The Development Requires

by Tanel Tammik

laravel php i18n localization multilingual

25/07 2015

0.1.1

0.1.1.0

Multilingual environment for Laravel framework

  Sources   Download

MIT

The Requires

 

The Development Requires

by Tanel Tammik

laravel php i18n localization multilingual

25/07 2015

0.1.0

0.1.0.0

Multilingual environment for Laravel framework

  Sources   Download

MIT

The Requires

 

The Development Requires

by Tanel Tammik