m1sh0u/laravel-polyglot-translator
Composer 安装命令:
composer require m1sh0u/laravel-polyglot-translator
包简介
Polyglot.php translator for Laravel
README 文档
README
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']);
Installation
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.
Usage
For more information about Polyglot.php' capabilities please follow its documentation
License
The MIT License (MIT). Please see License File for more information.
统计信息
- 总下载量: 2
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 2
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-05-28