efabrica/translatte
Composer 安装命令:
composer require efabrica/translatte
包简介
Translator for Nette framework
关键字:
README 文档
README
Translator for Nette framework.
Usage
use Efabrica\Translatte\Translator; use Efabrica\Translatte\Resource\NeonDirectoryResource; // Create new translator with default language $translator = new Translator('sk_SK'); // Register new resources where translations are stored $translator->addResource(new NeonDirectoryResource([__DIR__ . '/lang', __DIR__ . '/another/lang'])); $translator->addResource(new NeonResource(__DIR__ . '/dictionary.sk_SK.neon', 'sk_SK')); // Translate basic string $translator->translate('dictionary.forms.error']); // Translate with pluralization $translator->translate('key', 10); // Translate with parameters $translator->translate('key', ['name' => 'Peter']); // Translate with pluralization and parameters $translator->translate('key', 10, ['page' => 'login']); // Select translation language on the fly $translator->translate('key', 1, [], 'en_US');
Nette extension
extensions:
translation: Efabrica\Translatte\Bridge\Nette\TranslationExtension
# Minimal configuration
translation:
default: 'sk_SK' # mandatory
# Full configuration
translation:
default: 'sk_SK' # mandatory
fallback: # optional
- 'en_US'
- 'en_UK'
dirs:
- %appDir%/lang
cache: Efabrica\Translatte\Cache\NullCache() # optional
resolvers: # optional
- Efabrica\Translatte\Resolver\StaticResolver('sk_Sk')
resources: # optional
- Efabrica\Translatte\Resource\NeonDirectoryResource(%appDir%/localize)
recordTranslate: # optional
- Efabrica\Translatte\Record\NullRecord()
Syntactic sugar
dictionary.sk_SK.neon:
cart:
products_in_cart: 'V košíku je jeden produkt|V košíku sú %count% produkty|V košíku je %count% produktov'
Source: src/PluralForm.php
Example of count syntax:
sk: '1|2-4|0,5-Inf'
cz: '1|2-4|0,5-Inf'
en: '1|0,2-Inf'
Example of special count syntax (https://symfony.com/doc/3.1/components/translation/usage.html#pluralization):
en: '[-Inf,-10]big negative count|]-10,0[negative count|{0}zero count|{1}one count|{2,3,4}two,three,four count|]4,Inf]more than four count'
sk: '[-Inf,-10]veľký negatívny počet|]-10,0[negatívny počet|{0}nula počet|{1}jedna počet|{2,3,4}dva,tri,štyri počet|]4,Inf]viac ako štyri počet'
index.php:
// Translator setup
$translator = ...
// To params array is set count variable
$translator->translate('dictionary.cart.products_in_cart', 2); // V košíku sú 2 produkty
// Param count from params array is used to select right plural form
$translator->translate('dictionary.cart.products_in_cart', ['count' => 2]); // V košíku sú 2 produkty
// If we set both params nothing is override
$translator->translate('dictionary.cart.products_in_cart', 10, ['count' => 2]); // V košíku je 2 produktov
Main classes
Resolver
Resolves which language has translator to use.
Available resolvers:
- StaticResolver - Resolves to given static lang.
- ChainResolver - Multiple resolvers can be registered to this resolver. First resolver which returns non empty string is used.
Resource
Represents "storage" with translation strings. It can be anything - directory with translation files, database, redis or external api call.
Available resources:
- NeonResource - One neon file.
- NeonDirectoryResource - Multiple directories in which resource search neon files in format "{prefix}.{lang}.neon".
Cache
Used for cache generated directory.
efabrica/translatte 适用场景与选型建议
efabrica/translatte 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 75.05k 次下载、GitHub Stars 达 8, 最近一次更新时间为 2019 年 04 月 17 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「nette」 「translator」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 efabrica/translatte 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 efabrica/translatte 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 efabrica/translatte 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Nette Framework adapter for I18n package
Build forms from schema
Asynchronous MQTT client built on React
Form with datetime support and Bootstrap 4 form renderer
Identity authorizator class for Nette Framework
Database alias router extension for Nette Framework
统计信息
- 总下载量: 75.05k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 8
- 点击次数: 24
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-04-17