sepia / po-parser
PHP的Gettext *.PO文件解析器。
6.0.2
2023-08-01 13:12 UTC
Requires
- php: >=5.3
- symfony/polyfill-mbstring: ^1
Requires (Dev)
- fzaninotto/faker: ^1.7
- phpunit/phpunit: ^4.8.36
- squizlabs/php_codesniffer: ^2.0
README
PoParser是我为了满足个人需求而创建的一个项目:解析Gettext便携文件 (*.po 文件) 并使用PHP编辑其内容。
PoParser需要PHP >= 5.4,但也可能在5.3上运行。
变更日志
特性
它支持以下解析特性
- 头部区域。
- msgid,单行和多行。
- msgstr,单行和多行。
- msgctxt(消息上下文)。
- msgid_plural(复数形式)。
- #, keys(标志)。
- # keys(翻译者注释)。
- #. keys(从源代码提取的注释)。
- #: keys(引用)。
- #| keys(旧字符串),单行和多行。
- #~ keys(旧条目),单行和多行。
安装
composer require sepia/po-parser
用法
<?php // Parse a po file $fileHandler = new Sepia\PoParser\SourceHandler\FileSystem('es.po'); $poParser = new Sepia\PoParser\Parser($fileHandler); $catalog = $poParser->parse(); // Get an entry $entry = $catalog->getEntry('welcome.user'); // Update entry $entry = new Entry('welcome.user', 'Welcome User!'); $catalog->setEntry($entry); // You can also modify other entry attributes as translator comments, code comments, flags... $entry->setTranslatorComments(array('This is shown whenever a new user registers in the website')); $entry->setFlags(array('fuzzy', 'php-code'));
将更改保存回文件
使用PoCompiler
与FileSystem
一起将目录保存回文件
$fileHandler = new Sepia\PoParser\SourceHandler\FileSystem('en.po'); $compiler = new Sepia\PoParser\PoCompiler(); $fileHandler->save($compiler->compile($catalog));
文档
测试
测试使用PHPUnit进行。要执行测试,从命令行输入
php vendor/bin/phpunit
待办事项
- 添加与旧版歧义上下文格式兼容性。