Installing this package will enable using Polyglot.php to translate phrases through a Laravel application.
When installed, the trans
and trans_choice
will use the Polyglot.php
library to translate the given phrases:
trans('Hello, %{placeholder}', ['placeholder' => 'World']);
trans('1 vote %{period} |||| %{smart_count} votes %{period}', ['smart_count' => 4, 'period' => 'today'])
trans_choice('1 vote %{period} |||| %{smart_count} votes %{period}', 4, ['period' => 'today']);
You can install the package via composer:
composer require m1sh0u/laravel-polyglot-translator
In config/app.php
(Laravel) or bootstrap/app.php
(Lumen) you should replace Laravel's translation service provider,
Illuminate\Translation\TranslationServiceProvider::class,
by the one included in this package:
LaravelPolyglot\Providers\TranslationServiceProvider
Optionally you could publish the config file using the command:
php artisan vendor:publish --provider="LaravelPolyglot\Providers\TranslationServiceProvider" --tag="config"
This is the contents of the published config file:
return [
// @see https://github.com/M1Sh0u/polyglot.php for the meaning of each polyglot configuration parameter
'polyglot' => [
'allowMissing' => true,
'delimiter' => '||||',
'interpolation' => [
'prefix' => '%{',
'suffix' => '}'
],
'pluralRules' => [],
// Set a callback function to be called whenever a missing key is found.
// It could be useful if you need to store the missing keys into the database or to do something else.
// Please note that the return of this callback will be the actual string returned by the translator. @see https://github.com/M1Sh0u/polyglot.php
'onMissingKey' => null,
'onMissingKeyEnvs' => ['local', 'staging']
]
];
Note: publishing assets doesn't work out of the box in Lumen. Instead you have to copy the files from the repo.
For more information about Polyglot.php' capabilities please follow its documentation
The MIT License (MIT). Please see License File for more information.