跳转到主要内容

Force output to a specific locale

WP-CLI always outputs English because it doesn't support localization. But, because WordPress supports localization, you may see non-English output when performing specific commands.

For instance:

$ wp theme update --all
מעבר למצב תחזוקה...
מוריד עדכונים מ-https://downloads.wordpress.org/theme/hueman.3.3.25.zip...
Using cached file '/home/xxx/.wp-cli/cache/theme/hueman-3.3.25.zip'...
פתיחת עדכון...
התקנת גרסה חדשה...
הסרת הגרסה הקודמת של התבנית...
התבנית עודכנה בהצלחה.
ביטול מצב תחזוקה...
+--------+-------------+-------------+---------+
| name   | old_version | new_version | status  |
+--------+-------------+-------------+---------+
| hueman | 3.3.24      | 3.3.25      | Updated |
+--------+-------------+-------------+---------+
Success: Updated 1 of 1 themes.

To force WordPress to always output English at the command line, you need to filter the active locale.

Given a force-locale.php file:

<?php
WP_CLI::add_wp_hook( 'pre_option_WPLANG', function() {
    return 'en_US';
});

You can force the locale to en_US with:

wp --require=force-locale.php

One nice thing about this approach is that you can easily apply it across multiple WP installs using a config file.


📖 来源:WP-CLI Handbook · 作者:WP-CLI 开发组与贡献者 · 许可:MIT · 同步自上游提交 264cb13(2025-06-25)· 改动:仅格式转换

本页由 cocobook 外部书同步自动生成,此处只读;要修改请到菲码书稿仓 CocoBook/external-books 的 overlay 目录提合并请求。