wp-cli / i18n-command
为WordPress项目提供国际化工具。
Requires
- eftec/bladeone: 3.52
- gettext/gettext: ^4.8
- mck89/peast: ^1.13.11
- wp-cli/wp-cli: ^2.5
Requires (Dev)
- wp-cli/scaffold-command: ^1.2 || ^2
- wp-cli/wp-cli-tests: ^4
Suggests
- ext-json: Used for reading and generating JSON translation files
- ext-mbstring: Used for calculating include/exclude matches in code extraction
This package is auto-updated.
Last update: 2024-09-06 06:16:49 UTC
README
为WordPress项目提供国际化工具。
使用
此包实现了以下命令
wp i18n
为WordPress项目提供国际化工具。
wp i18n
示例
# Create a POT file for the WordPress plugin/theme in the current directory
$ wp i18n make-pot . languages/my-plugin.pot
wp i18n make-pot
为WordPress项目创建POT文件。
wp i18n make-pot <source> [<destination>] [--slug=<slug>] [--domain=<domain>] [--ignore-domain] [--merge[=<paths>]] [--subtract=<paths>] [--subtract-and-merge] [--include=<paths>] [--exclude=<paths>] [--headers=<headers>] [--location] [--skip-js] [--skip-php] [--skip-blade] [--skip-block-json] [--skip-theme-json] [--skip-audit] [--file-comment=<file-comment>] [--package-name=<name>]
扫描PHP、Blade-PHP和JavaScript文件中的可翻译字符串,如果源目录被检测为插件或主题,还会扫描主题样式表和插件文件。
选项
<source>
Directory to scan for string extraction.
[<destination>]
Name of the resulting POT file.
[--slug=<slug>]
Plugin or theme slug. Defaults to the source directory's basename.
[--domain=<domain>]
Text domain to look for in the source code, unless the `--ignore-domain` option is used.
By default, the "Text Domain" header of the plugin or theme is used.
If none is provided, it falls back to the project slug.
[--ignore-domain]
Ignore the text domain completely and extract strings with any text domain.
[--merge[=<paths>]]
Comma-separated list of POT files whose contents should be merged with the extracted strings.
If left empty, defaults to the destination POT file. POT file headers will be ignored.
[--subtract=<paths>]
Comma-separated list of POT files whose contents should act as some sort of denylist for string extraction.
Any string which is found on that denylist will not be extracted.
This can be useful when you want to create multiple POT files from the same source directory with slightly
different content and no duplicate strings between them.
[--subtract-and-merge]
Whether source code references and comments from the generated POT file should be instead added to the POT file
used for subtraction. Warning: this modifies the files passed to `--subtract`!
[--include=<paths>]
Comma-separated list of files and paths that should be used for string extraction.
If provided, only these files and folders will be taken into account for string extraction.
For example, `--include="src,my-file.php` will ignore anything besides `my-file.php` and files in the `src`
directory. Simple glob patterns can be used, i.e. `--include=foo-*.php` includes any PHP file with the `foo-`
prefix. Leading and trailing slashes are ignored, i.e. `/my/directory/` is the same as `my/directory`.
[--exclude=<paths>]
Comma-separated list of files and paths that should be skipped for string extraction.
For example, `--exclude=.github,myfile.php` would ignore any strings found within `myfile.php` or the `.github`
folder. Simple glob patterns can be used, i.e. `--exclude=foo-*.php` excludes any PHP file with the `foo-`
prefix. Leading and trailing slashes are ignored, i.e. `/my/directory/` is the same as `my/directory`. The
following files and folders are always excluded: node_modules, .git, .svn, .CVS, .hg, vendor, *.min.js.
[--headers=<headers>]
Array in JSON format of custom headers which will be added to the POT file. Defaults to empty array.
[--location]
Whether to write `#: filename:line` lines.
Defaults to true, use `--no-location` to skip the removal.
Note that disabling this option makes it harder for technically skilled translators to understand each message’s context.
[--skip-js]
Skips JavaScript string extraction. Useful when this is done in another build step, e.g. through Babel.
[--skip-php]
Skips PHP string extraction.
[--skip-blade]
Skips Blade-PHP string extraction.
[--skip-block-json]
Skips string extraction from block.json files.
[--skip-theme-json]
Skips string extraction from theme.json files.
[--skip-audit]
Skips string audit where it tries to find possible mistakes in translatable strings. Useful when running in an
automated environment.
[--file-comment=<file-comment>]
String that should be added as a comment to the top of the resulting POT file.
By default, a copyright comment is added for WordPress plugins and themes in the following manner:
```
Copyright (C) 2018 Example Plugin Author
This file is distributed under the same license as the Example Plugin package.
```
If a plugin or theme specifies a license in their main plugin file or stylesheet, the comment looks like
this:
```
Copyright (C) 2018 Example Plugin Author
This file is distributed under the GPLv2.
```
[--package-name=<name>]
Name to use for package name in the resulting POT file's `Project-Id-Version` header.
Overrides plugin or theme name, if applicable.
示例
# Create a POT file for the WordPress plugin/theme in the current directory.
$ wp i18n make-pot . languages/my-plugin.pot
# Create a POT file for the continents and cities list in WordPress core.
$ wp i18n make-pot . continents-and-cities.pot --include="wp-admin/includes/continents-cities.php" --ignore-domain
# Create a POT file for the WordPress theme in the current directory with custom headers.
$ wp i18n make-pot . languages/my-theme.pot --headers='{"Report-Msgid-Bugs-To":"https://github.com/theme-author/my-theme/","POT-Creation-Date":""}'
wp i18n make-json
从PO文件中提取JavaScript字符串并添加到单独的JSON文件中。
wp i18n make-json <source> [<destination>] [--purge] [--update-mo-files] [--pretty-print] [--use-map=<paths_or_maps>]
为了JavaScript国际化,WordPress需要将翻译拆分为每个JavaScript源文件的一个Jed格式的JSON文件。
有关WordPress JavaScript国际化的更多信息,请参阅 https://make.wordpress.org/core/2018/11/09/new-javascript-i18n-support-in-wordpress/。
选项
<source>
Path to an existing PO file or a directory containing multiple PO files.
[<destination>]
Path to the destination directory for the resulting JSON files. Defaults to the source directory.
[--purge]
Whether to purge the strings that were extracted from the original source file. Defaults to true, use `--no-purge` to skip the removal.
[--update-mo-files]
Whether MO files should be updated as well after updating PO files.
Only has an effect when used in combination with `--purge`.
[--pretty-print]
Pretty-print resulting JSON files.
[--use-map=<paths_or_maps>]
Whether to use a mapping file for the strings, as a JSON value, array to specify multiple.
Each element can either be a string (file path) or object (map).
示例
# Create JSON files for all PO files in the languages directory
$ wp i18n make-json languages
# Create JSON files for my-plugin-de_DE.po and leave the PO file untouched.
$ wp i18n make-json my-plugin-de_DE.po /tmp --no-purge
# Create JSON files with mapping
$ wp i18n make-json languages --use-map=build/map.json
# Create JSON files with multiple mappings
$ wp i18n make-json languages '--use-map=["build/map.json","build/map2.json"]'
# Create JSON files with object mapping
$ wp i18n make-json languages '--use-map={"source/index.js":"build/index.js"}'
wp i18n make-mo
从PO文件创建MO文件。
wp i18n make-mo <source> [<destination>]
选项
<source>
Path to an existing PO file or a directory containing multiple PO files.
[<destination>]
Path to the destination file or directory for the resulting MO files. Defaults to the source directory.
示例
# Create MO files for all PO files in the current directory.
$ wp i18n make-mo .
# Create a MO file from a single PO file in a specific directory.
$ wp i18n make-mo example-plugin-de_DE.po languages
# Create a MO file from a single PO file to a specific file destination
$ wp i18n make-mo example-plugin-de_DE.po languages/bar.mo
wp i18n make-php
从PO文件创建PHP文件。
wp i18n make-php <source> [<destination>]
选项
<source>
Path to an existing PO file or a directory containing multiple PO files.
[<destination>]
Path to the destination directory for the resulting PHP files. Defaults to the source directory.
示例
# Create PHP files for all PO files in the current directory.
$ wp i18n make-php .
Success: Created 3 files.
# Create a PHP file from a single PO file in a specific directory.
$ wp i18n make-php example-plugin-de_DE.po languages
Success: Created 1 file.
wp i18n update-po
从POT文件更新PO文件。
wp i18n update-po <source> [<destination>]
此行为类似于 msgmerge 命令。
选项
<source>
Path to an existing POT file to use for updating.
[<destination>]
PO file to update or a directory containing multiple PO files.
Defaults to all PO files in the source directory.
示例
# Update all PO files from a POT file in the current directory.
$ wp i18n update-po example-plugin.pot
Success: Updated 3 files.
# Update a PO file from a POT file.
$ wp i18n update-po example-plugin.pot example-plugin-de_DE.po
Success: Updated 1 file.
# Update all PO files in a given directory from a POT file.
$ wp i18n update-po example-plugin.pot languages
Success: Updated 2 files.
安装
此包包含在WP-CLI本身中,无需额外安装。
要安装此包的最新版本,而不仅仅是WP-CLI中包含的版本,请运行
wp package install [email protected]:wp-cli/i18n-command.git
贡献
我们感谢您主动为这个项目做出贡献。
贡献不仅限于代码。我们鼓励您以最适合您能力的方式做出贡献,例如编写教程、在您当地的聚会中进行演示、帮助其他用户解答支持问题或修订我们的文档。
要获得更详细的介绍,请查看WP-CLI贡献指南。此包遵循那些政策和指南。
报告错误
认为您发现了一个错误?我们非常希望您帮助我们修复它。
在创建新问题之前,您应该搜索现有问题,以查看是否已存在对该问题的解决方案,或者它是否已在更新的版本中修复。
一旦您进行了一些搜索,并发现没有为您的错误打开或修复的问题,请创建新问题。尽可能详细地提供详细信息,并在可能的情况下提供清晰的复现步骤。有关更多指导,请查看我们的错误报告文档。
创建pull request
想要贡献新功能吗?请先创建一个新问题,讨论该功能是否适合本项目。
一旦你决定投入时间完成你的拉取请求,请遵循我们创建拉取请求的指南,确保这是一个愉快的体验。有关在本地工作于此包的详细信息,请参阅"设置"。
支持
GitHub问题不是用于一般支持问题的,但你还可以尝试其他途径:https://wp-cli.org/#support
此README.md是从项目的代码库动态生成的,使用wp scaffold package-readme
(文档)。若要提出建议,请提交针对代码库相应部分的拉取请求。