Require this package with composer using the following command:
composer require deployteam/laravel-polytranslate
After updating composer, add the service provider to the providers
array in config/app.php
DeployTeam\PolyTranslate\ServiceProvider::class,
If you want to use the facade, add this to your facades in app.php:
'PolyTranslate' => DeployTeam\PolyTranslate\Facade::class,
>= Laravel 5.5 uses Package Auto-Discovery, so it's not required to manually add the ServiceProvider and the Facade.
Using PolyTranslate you can add multiple paths for language loading:
PolyTranslate::addPath(['themes/base/lang', 'themes/child/lang']); // without namespace
PolyTranslate::addNamespace('theme', ['themes/base/lang', 'themes/child/lang']); // with namespace
Laravel will start searching the directories for languages, and will merge anything it finds.
// themes/base/lang/en/header.php
return [
'greetings' => 'Hello',
'login' => 'Login'
];
// themes/child/lang/en/header.php
return [
'login' => 'Authenticate',
'register' => 'Register'
];
The final result will be:
[
'greetings' => 'Hello',
'login' => 'Authenticate',
'register' => 'Register'
]
To use the translation, you just use the built-in Laravel functionality:
@lang('header.greetings') <!-- Without namespace -->
@lang('theme::header.greetings') <!-- With namespaces -->
The Laravel PolyTranslate is open-sourced software licensed under the MIT license