Force output to a specific locale Edit

WP-CLIWP-CLI WP-CLI is the Command Line Interface for WordPress, used to do administrative and development tasks in a programmatic way. The project page is 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
מעבר למצב תחזוקה...
מוריד עדכונים מ-
Using cached file '/home/xxx/.wp-cli/cache/theme/'...
פתיחת עדכון...
התקנת גרסה חדשה...
הסרת הגרסה הקודמת של התבנית...
התבנית עודכנה בהצלחה.
ביטול מצב תחזוקה...
| 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 filterFilter Filters are one of the two types of Hooks They provide a way for functions to modify data of other functions. They are the counterpart to Actions. Unlike Actions, filters are meant to work in an isolated manner, and should never have side effects such as affecting global variables and output. the active locale.

Given a force-locale.php file:

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.

Last updated: