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:

WP-CLI terminal output in Hebrew

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)

WP-CLI with BiDi suported terminal

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.

And you can run all your commands with:

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

 

Related Post

2 Responses

  1. Hatul says:

    Thanks but if I setting the WPLANG to english then the translation not update.

    • Rabin says:

      I didn’t verify this, but if it so, it should be mention in the issue opened on github.

Leave a Reply

Your email address will not be published. Required fields are marked *