felicity-php / felicity-translate
PHP的翻译功能
1.1.0
2017-11-29 15:02 UTC
Requires
- felicity-php/felicity-config: ^1.0
- roave/security-advisories: dev-master
Requires (Dev)
- felicity-php/felicity-twig: ^1.0
- phpunit/phpunit: ^6.1
This package is not auto-updated.
Last update: 2024-09-15 05:04:37 UTC
README
Felicity translate为PHP提供了设置和获取翻译的方法
用法
使用Felicity Config设置您的区域设置、默认区域设置和翻译,然后使用翻译类来获取您的翻译。
<?php use felicity\config\Config; use felicity\translate\Translate; Config::set('lang.defaultLocale', 'en'); Config::set('lang.locale', 'de'); Config::set('lang.translations.en.myCategory', [ 'myTranslationKey' => 'Translation of something', 'anotherTranslationKey' => 'Translation of something with {{var}}', ]); Config::set('lang.translations.de.myCategory', [ 'myTranslationKey' => 'Übersetzung von etwas', 'anotherTranslationKey' => 'Übersetzung von etwas mit {{var}}', ]); $myTranslation = Translate::get('myCategory', 'myTranslationKey'); $anotherTranslation = Translate::get('myCategory', 'anotherTranslationKey', [ '{{var}}' => 'someVal', ]);
Felicity Twig中的用法
如果您已将Felicity Twig引入到项目中,您可以使用以下方式在twig中使用翻译
{# As a function #} {{ translate('myTranslation', 'optionalCategory') }} {# As a filter #} {{ 'myTranslation'|translate('optionalCategory') }}
如果您未提供类别,将使用默认值,除非您使用Felicity Config设置默认值,默认为dev
<?php use felicity\config\Config; Config::set('lang.defaultTwigCategory', 'myCategory');
许可证
版权所有 2017 BuzzingPixel, LLC
根据Apache License 2.0(“许可证”)许可;除非遵守许可证,否则不得使用此文件。您可以在https://apache.ac.cn/licenses/LICENSE-2.0 获取许可证的副本。
除非适用法律要求或书面同意,否则在许可证下分发的软件按“原样”分发,不提供任何明示或暗示的保证或条件。有关许可证的具体语言和限制,请参阅许可证。