Force WP-CLI output to be in English

I need to manage several insensate of WordPress installations, some of them are in Hebrew and one in Arabic, and when using wp-cli to manage the installation, e.g when running plugin update, wp-cli will use WordPress translation strings with the current WP installed language. So for example a Hebrew WP installation will look like this:

Using WP-CLI with a terminal not supporting BiDi

One way to over come this, is to use a terminal which support BiDi (e.g mlterm or Konsole)

Using WP-CLI with a terminal (like mlterm) supporting BiDi

That’s make is a bit better, but still I prefer all my terminal work to be in English.

I tried to add a snippet of code to wp-config.php to detect if the WP installation is running via WP-CLI and force the WPLANG to be en_USbut that didn’t work either. So I googled a bit more and didn’t found any way to resolve this my self, so I asked for some help in the wp-cli slack channel and they gave me a work around which seems to work, and they also open an issue (which you are welcome to support to push this forward) in github about defaulting to English for wp-cli in terminal.

TL;DR

Any way, the short answer is to use the --require option of wp-cli to load a file which uses a hook to set WPLANG before any one set it.

force-locale.php

PHP

1

2

3

4

<?php

WP_CLI::add_wp_hook('pre_option_WPLANG',function(){

return'en_US';

});

And you can run all your commands with:

1

wp--require=force-locale.php{...}

or you can go one step forward, and set it as default for all wp commands by setting it in the global ~/.wp-cli/config.yml file