coffreo / js-translation-extractor
从 JavaScript 源代码中提取翻译
0.3.0
2022-02-10 15:21 UTC
Requires
- php: ^5.6 || ^7.0 || ^8.0
- symfony/finder: ^2.7 || ^3.0 || ^4.0 || ^5.0 || ^6.0
Requires (Dev)
- coffreo/php-cs-fixer-config: ^2.2
- symfony/phpunit-bridge: ^3.4 || ^4.0
This package is auto-updated.
Last update: 2024-09-10 21:31:02 UTC
README
由 Coffreo 提供
为 willdurand/js-translation-bundle
提供的 JavaScript 翻译提取器
此包是一个小型项目,旨在将一些精彩的正则表达式存储在一个地方,以便正确地从 JavaScript 源文件中导出翻译字符串和元数据。
它可以单独使用,但主要目标是用于以下场景
安装
-
如果您想单独使用此包或将其集成到自己的翻译提取系统中,您只需手动安装此包即可
composer require coffreo/js-translation-extractor
-
与 Symfony JMSTranslationBundle 一起使用
-
与 Symfony PHP Translation 一起使用
特性
- 像专业人士一样从 JavaScript 文件中提取以下字符串
trans('MESSAGE', {param: 'foo'}, 'DOMAIN') // ^ 1st parameter is translation message // ^ 3rd parameter is translation domain transChoice('MESSAGE_WITH_PLURALS', 3, {param: 'foo'}, 'DOMAIN') // ^ 1st parameter is translation message // ^ 4th parameter is translation domain // others parameters aren't extracted because they are useless.
注意,这是 js-translation-bundle
使用的语法
- 允许字符串定界符为
"
或'
- 提取多行命令
使用方法
use Coffreo\JsTranslationExtractor\Extractor\JsTranslationExtractor; use Coffreo\JsTranslationExtractor\Model\TranslationCollection; $extractor = new JsTranslationExtractor(); $translationCollection = new TranslationCollection(); $extractor->extract(<<<FILECONTENT import Translator from 'bazinga-translator'; export default () => Translator.trans('This is awesome', {}, 'foo'); export { bad: () => Translator.trans('This is ugly'); }; FILECONTENT , $translationCollection); $first = $translationCollection->first(); $first->getMessage(); // This is awesome $first->getLine(); // 3 $first->getContext(); // ['domain' => 'foo'] $second = $translationCollection->get(1); $second->getMessage(); // This is ugly $second->getLine(); // 5 $second->getContext(); // []
发现了一个错误
请填写一个包含重现错误信息的 issue。
如果您的翻译字符串没有被正确提取,请提供失败的字符串示例。
开发
- 克隆仓库
- 执行
make [install] # to init composer after install make test # to run test
待办事项
- 找到一种方法来添加和提取描述/含义值
许可证
此项目受 MIT 许可证的许可 - 有关详细信息,请参阅 LICENSE 文件。