2017 © Pedro Pelรกez
 

library laravel-multilang

Package to integrate multi language (multi locale) functionality in Laravel 5.x

image

longman/laravel-multilang

Package to integrate multi language (multi locale) functionality in Laravel 5.x

  • Sunday, February 18, 2018
  • by LONGMAN
  • Repository
  • 6 Watchers
  • 40 Stars
  • 3,960 Installations
  • PHP
  • 1 Dependents
  • 1 Suggesters
  • 8 Forks
  • 3 Open issues
  • 40 Versions
  • 11 % Grown

The README.md

Laravel 5.x MultiLanguage

Build Status Code Coverage Code Quality Latest Stable Version Total Downloads Downloads Month License, (*1)

This version of MultiLang package requires minimum PHP 7.0. For older PHP versions use MultiLang 1.x, (*2)

This is a very useful package to integrate multi language (multi locale) functionality in Laravel 5.x. It includes a ServiceProvider to register the multilang and Middleware for automatic modification routes like http://site.com/en/your-routes., (*3)

This package uses database for storing translations (it caches data on production environment for improving performance) Also package automatically adds in database missing keys (on the local environment only)., (*4)

Table of Contents

Installation

Install this package through Composer., (*5)

Edit your project's composer.json file to require longman/laravel-multilang, (*6)

Create composer.json file:, (*7)

{
    "name": "yourproject/yourproject",
    "type": "project",
    "require": {
        "longman/laravel-multilang": "~2.0"
    }
}

And run composer update, (*8)

Or run a command in your command line:, (*9)

composer require longman/laravel-multilang

In Laravel the service provider and facade will automatically get registered., (*10)

Copy the package config to your local config with the publish command:, (*11)

php artisan vendor:publish --provider="Longman\LaravelMultiLang\MultiLangServiceProvider"

After run multilang migration command, (*12)

php artisan multilang:migration

Its creates multilang migration file in your database/migrations folder. After you can run, (*13)

php artisan migrate

Also if you want automatically change locale depending on url (like http://site.com/en/your-routes) you must add middleware in app/Http/Kernel.php, (*14)

I suggest add multilang after CheckForMaintenanceMode middleware, (*15)

protected $middleware = [
    \Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class,
    \Longman\LaravelMultiLang\Middleware\MultiLang::class,
];

In your RoutesServiceProvider modify that:, (*16)

MultiLang::routeGroup(function($router) {
    require app_path('Http/routes.php');
});

or directly in app/Http/routes.php file add multilang group:, (*17)

MultiLang::routeGroup(function($router) {
    // your routes and route groups here
});

Or if you want only translate strings without automatic resolving locale and redirect, you can manually set locale in your application like:, (*18)

App::setLocale('en');

Usage

Translating

Everywhere in application you can use t() helper function like:, (*19)

$string = t('Your translatable string');

You can use markers for dynamic texts and pass any data like, (*20)

$string = t('The :attribute must be a date after :date.', ['attribute' => 'Start Date', 'date' => '7 April 1986']);

which will be return The Start Date must be a date after 7 April 1986., (*21)

Blade Templates

In blade templates you can use just @t() notation like, (*22)

@t('Your translatable string')

which is equivalent to {{ t('Your translatable string') }}, (*23)

URL Generation

Also you can use lang_url() helper function for appending current lang marker in urls automatically., (*24)

$url = lang_url('users'); // which returns /en/users depending on your language (locale)

You can force locale and get localized url for current url for example., (*25)

$url = lang_url('users', [], null, 'ka'); // which returns /ka/users ignoring current locale

or, (*26)

$url = lang_url('en/users', [], null, 'ka'); // also returns /ka/users

Also you use named routes via lang_route() function, (*27)

$url = lang_route('users'); // which returns en.users depending on your language (locale)

Also Request::locale() always will return current locale., (*28)

Note: Texts will be selected after firing Laravel's LocaleUpdated event. Therefore you should use MultiLang middleware, or manually set locale in the application., (*29)

Text Scopes

If you want group translations by some scope, in package available defining of scopes. For example to define scope admin in application, you should call:, (*30)

app('multilang')->setScope('admin');

before setting the locale., (*31)

Note: Default scope is global, (*32)

Import/Export Texts

For versioning texts with source code (git/svn) and easy management, there is possible import texts from yml file and also export in the file., (*33)

yml file format is:, (*34)

-
  key: 'authorization'
  texts:
    en: 'Authorization'
    ge: 'แƒแƒ•แƒขแƒแƒ แƒ˜แƒ–แƒแƒชแƒ˜แƒ'
-
  key: 'registration'
  texts:
    en: 'Registration'
    ge: 'แƒ แƒ”แƒ’แƒ˜แƒกแƒขแƒ แƒแƒชแƒ˜แƒ'

Run commands for possible options and more information:, (*35)

php artisan help multilang:import

php artisan help multilang:export

TODO

write more tests, (*36)

Troubleshooting

If you like living on the edge, please report any bugs you find on the laravel-multilang issues page., (*37)

Contributing

Pull requests are welcome. See CONTRIBUTING.md for information., (*38)

License

Please see the LICENSE included in this repository for a full copy of the MIT license, which this project is licensed under., (*39)

Credits

Full credit list in CREDITS, (*40)

The Versions

18/02 2018
04/12 2017

dev-master

9999999-dev https://github.com/akalongman/laravel-multilang

Package to integrate multi language (multi locale) functionality in Laravel 5.x

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel language translation locale localization package multilang

04/12 2017

1.3.3

1.3.3.0 https://github.com/akalongman/laravel-multilang

Package to integrate multi language (multi locale) functionality in Laravel 5.x

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel language translation locale localization package multilang

26/11 2017

1.3.2

1.3.2.0 https://github.com/akalongman/laravel-multilang

Package to integrate multi language (multi locale) functionality in Laravel 5.x

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel language translation locale localization package multilang

25/11 2017

1.3.1

1.3.1.0 https://github.com/akalongman/laravel-multilang

Package to integrate multi language (multi locale) functionality in Laravel 5.x

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel language translation locale localization package multilang

25/11 2017

1.3.0

1.3.0.0 https://github.com/akalongman/laravel-multilang

Package to integrate multi language (multi locale) functionality in Laravel 5.x

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel language translation locale localization package multilang

14/11 2017

1.2.11

1.2.11.0 https://github.com/akalongman/laravel-multilang

Package to integrate multi language (multi locale) functionality in Laravel 5.x

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel language translation locale localization package multilang

04/10 2017

1.2.10

1.2.10.0 https://github.com/akalongman/laravel-multilang

Package to integrate multi language (multi locale) functionality in Laravel 5.x

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel language translation locale localization package multilang

10/09 2017

1.2.9

1.2.9.0 https://github.com/akalongman/laravel-multilang

Package to integrate multi language (multi locale) functionality in Laravel 5.x

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel language translation locale localization package multilang

10/09 2017

1.2.8

1.2.8.0 https://github.com/akalongman/laravel-multilang

Package to integrate multi language (multi locale) functionality in Laravel 5.x

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel language translation locale localization package multilang

10/09 2017

1.2.7

1.2.7.0 https://github.com/akalongman/laravel-multilang

Package to integrate multi language (multi locale) functionality in Laravel 5.x

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel language translation locale localization package multilang

10/09 2017

1.2.6

1.2.6.0 https://github.com/akalongman/laravel-multilang

Package to integrate multi language (multi locale) functionality in Laravel 5.x

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel language translation locale localization package multilang

05/09 2017

1.2.5

1.2.5.0 https://github.com/akalongman/laravel-multilang

Package to integrate multi language (multi locale) functionality in Laravel 5.x

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel language translation locale localization package multilang

09/07 2017

1.2.4

1.2.4.0 https://github.com/akalongman/laravel-multilang

Package to integrate multi language (multi locale) functionality in Laravel 5.x

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel language translation locale localization package multilang

25/06 2017

1.2.3

1.2.3.0 https://github.com/akalongman/laravel-multilang

Package to integrate multi language (multi locale) functionality in Laravel 5.x

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel language translation locale localization package multilang

25/06 2017

1.2.2

1.2.2.0 https://github.com/akalongman/laravel-multilang

Package to integrate multi language (multi locale) functionality in Laravel 5.x

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel language translation locale localization package multilang