smarty-gettext/tsmarty2c

Smarty Gettext 翻译字符串提取工具

0.2.2 2021-12-24 11:57 UTC

This package is auto-updated.

Last update: 2024-08-24 17:49:37 UTC


README

tsmarty2c.php - 一个命令行工具,用于从 smarty 源文件中提取 gettext 字符串并将其转换为 .pot (PO-模板)。

此实用程序将扫描模板中的 {t}...{/t} 占位符以查找翻译字符串,并输出一个 .pot 文件(.po 模板)。

用法

./vendor/bin/tsmarty2c.php -o template.pot <filename or directory> <file2> <...>

如果参数是目录,则将递归地解析目录内的模板文件。

在输出中添加了特殊的 PO 标签,以告知提取翻译的位置。大多数 PO 编辑工具都可以尊重这些信息。

如果您希望扫描 .php.phtml 文件以查找本地 gettext 调用,您可以组合 tsmarty2cxgettext 调用的结果

./vendor/bin/tsmarty2c.php -o smarty.pot ...
xgettext --add-comments=TRANSLATORS: --keyword=gettext --keyword=_  --output=code.pot ...
msgcat -o template.pot code.pot smarty.pot
rm -f code.pot smarty.pot

默认情况下,tsmarty2c 扫描 .tpl 文件,如果您希望使用其他文件,您可以在 Unix 中使用 xargs

find templates -name '*.tpl.html' -o -name '*.tpl.text' -o -name '*.tpl.js' -o -name '*.tpl.xml' | xargs tsmarty2c.php -o smarty.pot

请参阅 Eventum 项目中的实现方法。

安装

  1. 作为包依赖项

    composer require --dev smarty-gettext/tsmarty2c
    ./vendor/bin/tsmarty2c.php
    
  2. 直接从此存储库

    git clone https://github.com/smarty-gettext/tsmarty2c
    cd tsmarty2c
    composer install --no-dev
    ./bin/tsmarty2c.php
    

开发

  1. 克隆此存储库
  2. 获取 composer
  3. 安装 composer 依赖项: php composer.phar install
  4. 开始使用: php bin/tsmarty2c.php