26b / i18n-midoru
轻松处理翻译操作(下载和上传)。
v1.0-rc
2022-10-10 15:41 UTC
Requires
Requires (Dev)
- phpunit/phpunit: ^9.0
This package is auto-updated.
Last update: 2024-09-06 11:19:56 UTC
README
此库提供了一些辅助函数/类,用于处理基于配置文件的导出和导入翻译操作。目前我们仅支持Localise作为翻译的源。
⚠️ 此库正在积极开发中,因此API可能会发生变化。
如何使用?
本质上存在三种接口,它们仅在如何将选项传递给翻译系统方面有所不同。
-
使用包含所有配置的JSON文件。
{ "project_name": { "export": { "ext": "mo", "format": "gettext" } } }
use TwentySixB\Translations\Translations; use TwentySixB\Translations\Input\File; // Make POT $translations = new Translations( new File( 'path_to_file.json' ) ); $translations->make_pots(); $translations->upload();
-
使用PHP作为接口,并使用PHP数据结构进行配置。
use TwentySixB\Translations\Translations; use TwentySixB\Translations\Input\Dataset; // Make POT $translations = new Translations( new Dataset( [ 'project_name' => [ 'export' => [ 'ext' => 'mo', 'format' => 'gettext', ] ] ] ) ); $translations->make_pots(); $translations->upload();
-
使用自定义命令并从传递给它的选项中获取配置。
创建您的两个PHP命令文件。
<?php // upload.php use TwentySixB\Translations\Translations; use TwentySixB\Translations\Input\CLI; $translations = new Translations( new CLI() ); $translations->make_pots(); $translations->upload();
<?php // download.php use TwentySixB\Translations\Translations; use TwentySixB\Translations\Input\CLI; $translations = new Translations( new CLI() ); $translations->download();
现在您可以从命令行像这样运行它们
# Make POTs and upload files. $ php run upload.php --name="project_name" --ext="mo" --format="gettext" # Download translations form the system for two locales. $ php run download.php --name="project_name" --ext="mo" --format="jed" --locale="pt_PT" --locale="en"
选项
无论使用何种方法将信息传递给Translations
类,您都可以使用以下选项来配置您想要执行的操作。
导出(export)
locale
string
|array
- 导出语言(们)的短码。参见 Locale Export API。
ext
string
- Localise API接受的扩展。参见 Locale Export API。
format
string
- Localise API接受的格式。参见 Locale Export API。
domain
string
|optional
- 导出域。附加在文件名开头,在地区之前。见下文。
filename
string
|optional
- 导出文件名。优先于域。见下文。
js-handle
string
|optional
- 附加在文件名末尾,在扩展名之前,前面有一个连字符。见下文。
path
string
|optional
|default:
./- 文件保存的目录路径。
wrap-jed
bool
|optional
|default:
true- 指定是否将导出的内容包裹在具有'locale_data'键的数组中。
name
string
|required
if using CLI- 项目的名称。
文件路径将包含以下内容
path ?(domain|filename-) locale ?(-js-handle) .ext
?(.*)
表示可选值。
导入(import)
locale
string
|array
- 导入语言(们)的短码。参见 Locale Import API。
ext
string
- Localise API接受的扩展。参见 Locale Import API。
domain
string
|optional
- 导入域。附加在文件名开头,在地区之前。见下文。
filename
string
|optional
- 导入文件名。优先于域。见下文。
js-handle
string
|optional
- 附加在文件名末尾,在扩展名之前,前面有一个连字符。见下文。
path
string
|optional
|default:
./- 文件保存的目录路径。
name
string
|required
if using CLI- 项目的名称。
文件路径将包含以下内容
path ?(domain|filename-) locale ?(-js-handle) .ext
?(.*)
表示可选值。
创建.pot文件(make_pots)
domain
string
- 为
wp i18n make-pots
命令指定的域。
source
string
wp i18n make-pots
命令的源路径。字符串将被从中提取进行翻译的目录。
destination
string
wp i18n make-pots
命令的目标路径。pot文件将被保存的位置。
skip-js
:bool
|optional
|default:
true- 选项
--skip-js
是否将被传递给wp i18n make-pots
命令。这样,JS代码中的字符串将不会被考虑进行翻译。
待办事项
- 可能还有其他API参数。
- 连接所有参数,并指出在某种情况下哪些不可用。