arteq/tmx-utils
Composer 安装命令:
composer require arteq/tmx-utils
包简介
Read and write TMX files, simple element manipulation
关键字:
README 文档
README
Description
Simple library for handling Translation Memory eXchange files used in translation industry. Can be used to read/write or split large files into smaller ones.
More on TMX standard: http://xml.coverpages.org/tmxSpec971212.html
Installation
Run composer to fetch project from packagist:
$ composer require arteq/tmx-utils
Optionally you can run tests (phpUnit, CS-Fixer, PHPStan):
$ make
Note: code quality tests require PHP 7.x. If you run PHP 5.6 you can use simplified composer_php56.json file instead and only run phpUnit tests:
$ env COMPOSER=composer_php56.json composer install
$ make phpunit
The library itself will run just fine on both PHP 5.x and 7.x.
Reader
The Reader class is used to extract translation units and return them as multidimensional array. First level of array keys consists of translation unit id, second level key is segment language code and value is the segment text itself. All additional properties and element attributes are ignored.
Usage
$reader = new ArteQ\Tmx\Reader('file.tmx');
// get all translation units
$units = $reader->get();
var_dump($unit);
// get single translation unit by its id
$unit = $reader->get('tu-123');
var_dump($unit);
// get all translation units for given language code
$unitsLang = $reader->getLang('en_UK');
var_dump($unitsLang);
Writer
The Writer class is used to create TMX file. Translation units can be added to internal data memory one by one using set($tuid, $xmlLang, $value = '') method or all at once from array using setArray(array $data). This approach enables to futher manipulate data, ex. fetch translation unit by it's id, change or delete it. To save data to file use write().
Usage - simple
$tmx = new Writer('file.tmx');
// set two segments for one translation unit identified by id 'tuid-123'
$tmx->set('tuid-123', 'pl_PL', 'Tekst polski');
$tmx->set('tuid-123', 'en_EN', 'English text');
// add additional attribute
$tmx->setAttribute('id-123', 'creationid', 'user-123');
// add additional property
$tmx->setProperty('id-123', 'client', 'ACME Ltd.');
// save data to file
$tmx->write();
In case of very large files with a lot of translation units that you only want to save to TMX file without any data manipulation streamed approach should be used. Each translation unit is added one by one and flushed to disk every 1000 units. This keeps the memory usage low as the whole dataset doesn't have to be kept in memory.
Usage - streamed
// expected data format
$data = [
'tuid-1' => [
'pl' => 'tekst polski',
'en' => 'english text',
'_attributes' => [
'attr1' => 'value1',
'attr2' => 'value2',
],
],
'tuid-2' => [
'pl' => 'inny tekst',
'_properties' => [
'type1' => 'value1',
'type2' => 'value2',
],
],
'tuid-3' => [
'pl' => 'kolejny tekst',
'en' => 'another text',
]
];
$tmx = new Writer('file.tmx');
$tmx->writeStart();
foreach ($data as $tuid => $tuvs)
{
$tmx->writeTu($tuid, $tuvs);
}
$tmx->writeEnd();
See tests/WriterTest.php for more examples.
Credits
The initial version of TMX reader/writer was based on project from Maxime Maupeu and can be found on his GitHub
Splitter
Splitter can be used to read large TMX (file size of many GB) and save it in chunks of smaller files for easier manipulation in 3rd software. It uses stream XMLReader and XMLWriter so memory usage is very low as there is no need to read entire file into memory. The TMX header element of input file is inserted in every output file without any changes.
The number of translation units (<tu>) that will be saved in each chunk is set by setLimit() function.
Usage
$splitter = new ArteQ\Tmx\Splitter('large.tmx');
$splitter->setLimit(1000);
$splitter->split();
var_dump($splitter->getStats());
Notes
- UTF-8 encoding is assumed both in input and output files.
- Output files will have a number appended in their name to indicate order (ex.:
file_000.tmx,file_001.tmx, etc..). - Output files may not have perfect indent of XML elements due to the writeRaw() function used for simplicity.
arteq/tmx-utils 适用场景与选型建议
arteq/tmx-utils 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 24 次下载、GitHub Stars 达 0, 最近一次更新时间为 2020 年 04 月 02 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「translation」 「tmx」 「split file」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 arteq/tmx-utils 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 arteq/tmx-utils 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 arteq/tmx-utils 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A custom URL rule class for Yii 2 which allows to create translated URL rules
A Laravel Eloquent model trait for translatable resource
A server-side A/B/n testing tool
mobilpay split
A/B Testing of content elements
Analyze user input string, and split it into Russian first name, second name and last name
统计信息
- 总下载量: 24
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 5
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-04-02