m1sh0u / laravel-polyglot-translator
Laravel 的 Polyglot.php 翻译器
v1.1
2020-06-01 09:29 UTC
Requires
- illuminate/translation: ~5.8.0|^6.0|^7.0
- m1sh0u/polyglot-php: 1.*
This package is auto-updated.
Last update: 2024-08-29 05:19:01 UTC
README
安装此包将启用通过 Laravel 应用程序使用 Polyglot.php 来翻译短语的特性。
安装后,trans
和 trans_choice
将使用 Polyglot.php
库来翻译给定的短语
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']);
安装
您可以通过 composer 安装此包
composer require m1sh0u/laravel-polyglot-translator
在 config/app.php
(Laravel) 或 bootstrap/app.php
(Lumen) 中,您应该替换 Laravel 的翻译服务提供者,
Illuminate\Translation\TranslationServiceProvider::class,
为这个包中包含的提供者
LaravelPolyglot\Providers\TranslationServiceProvider
可选地,您可以使用以下命令发布配置文件
php artisan vendor:publish --provider="LaravelPolyglot\Providers\TranslationServiceProvider" --tag="config"
这是已发布配置文件的内容
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'] ] ];
注意:在 Lumen 中,默认情况下发布资源不起作用。相反,您必须从仓库复制文件。
用法
有关 Polyglot.php 功能的更多信息,请参阅其 文档
许可
MIT 许可证 (MIT)。有关更多信息,请参阅许可文件。