deployteam / laravel-polytranslate
Add multiple locations for Laravel localization namespace
Fund package maintenance!
Opencollective
Paypal
Requires
- php: >=7.1
Requires (Dev)
- laravel/framework: ~7.0
This package is auto-updated.
Last update: 2024-11-05 23:06:49 UTC
README
Install
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.
Usage
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 -->
License
The Laravel PolyTranslate is open-sourced software licensed under the MIT license