lloc/composer-i18n-scripts
最新稳定版本:1.0.0
Composer 安装命令:
composer require lloc/composer-i18n-scripts
包简介
Simplify the internationalization of your WordPress plugin or theme using WP-CLI — powered by Composer.
README 文档
README
Automate the internationalization workflow of your WordPress plugin or theme by wiring WP-CLI translation tools into familiar Composer commands.
Requirements
- PHP 7.4+ and Composer 2.6+ (Composer plugin API 2.6 is required)
- WP-CLI 2.12+ available on your
$PATH - A WordPress plugin or theme with
Text DomainandDomain Pathheaders defined
Installation
composer require --dev lloc/composer-i18n-scripts
Composer automatically registers the plugin; no manual bootstrap code is needed. Running composer install on the project will keep the plugin active for all contributors.
Configuration
The plugin inspects your project root to infer settings:
- Themes: reads
style.css - Plugins: reads the main plugin file (matching the directory name or
index.php)
Provide headers like the following so WP-CLI receives the right text domain and language directory:
/* Plugin Name: Sample Plugin Text Domain: sample-plugin Domain Path: /languages */
If no metadata is found, defaults are Text Domain: messages and Domain Path: /languages.
Usage
Run the commands from the WordPress project root so that wp can load your environment.
| Command | Purpose |
|---|---|
composer i18n:make-pot |
Scan the source directory and generate languages/<domain>.pot. |
composer i18n:create-po <locale> |
Copy the .pot file to a locale-specific .po file (e.g. de_DE). |
composer i18n:update-po |
Merge the current .pot changes into every .po in languages/. |
composer i18n:make-mo |
Compile all .po files into .mo binaries. |
composer i18n:make-php |
Export .po translations into PHP array files for performance-sensitive setups. |
composer i18n:make-json |
Build JavaScript translation catalogs (*.json) without purging existing assets. |
Example workflow:
composer i18n:make-pot composer i18n:update-po composer i18n:make-json composer i18n:make-mo
Development
composer install– install dependencies and register the plugincomposer qa– PHPCS (WordPress Coding Standards) + PHPStan level 10composer tests– run PHPUnit suite undertests/Commandscomposer tests:coverage– generate HTML coverage intests/coverage/composer cs:fix– automatically fix style violations
Refer to AGENTS.md for contributor conventions, coding standards, and pull request expectations.
Troubleshooting
- “Text domain is not set”: ensure your plugin/theme headers declare
Text DomainandDomain Path. - WP-CLI not found: verify
wpis installed globally or provide an absolute path (e.g. symlinkwpinto/usr/local/bin). - Translations not picking up new strings: rerun
composer i18n:make-potbefore updating.pofiles so the template is up to date.
统计信息
- 总下载量: 85
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: GPL-2.0-or-later
- 更新时间: 2025-10-22