Install & update WordPress languages with WP-CLI

My workflow now consists of the following lines in deploy-hooks/build-after.yml (which must be included in your deploy.yml):

- name: Install language de_CH
  command: php ~/bin/wp core language install de_CH
  args:
    chdir: "{{ deploy_helper.new_release_path }}"

- name: Install language de_DE
  command: php ~/bin/wp core language install de_DE
  args:
    chdir: "{{ deploy_helper.new_release_path }}"

- name: Update language files
  command: php ~/bin/wp core language update
  args:
    chdir: "{{ deploy_helper.new_release_path }}"

Works like a charm!

If anyone knows how to improve this (like merge the 3 commands), feel free to share. :slight_smile:

You may have to change the path from php ~/bin/wp to where WP-CLI is installed on your server.


I use Bernhard Kau’s Language Fallback plugin to… well… define a fallback language. Same goes for Spanish (Mexico) es_MX to Spanish es_ES.

3 Likes

@scherii, thank you for sharing such a handy way to update languages. I have two questions:

  1. Do you gitignore web/app/languages/?
  2. Don’t you update languages locally?

Also I think you can chain 3 commands altogether with ;

- name: Install & update languages de_CH, de_DE
  command: wp core language install de_CH; wp core language install de_DE; wp core language update
  args:
    chdir: "{{ deploy_helper.new_release_path }}"

assuming you have alias for wp cli

Hi @Isk1n, I’m glad that this is of use for you! :slight_smile:

  1. I gitignore web/app/languages/* because I wanted to create that folder so WP-CLI can put the language files in there.

  2. Only when I need it. I found that it didn’t really matter to me locally, so I just do it the first time I start a project via SSH (vagrant ssh). It could probably be done automatically on vagrant up via a hook, like the deploy.yml-hooks. I don’t know how to do this in dev.yml – yet.
    @swalkinshaw ?

And thanks for your one-line simplification! :thumbsup:


EDIT: Unfortunately the one-liner doesn’t seem to work.

fatal: [staging.domain.tld]: FAILED! => {"changed": false, "cmd": "wp core language install 'de_CH;' wp core language install 'de_DE;' wp core language update", "failed": true, "rc": 2}

For now I’ll just stick with the extended version. :slight_smile:

These quotes

look weird. It seems parser treats semicolon as part of the lang code argument

Yes, it occurs with &&, too.

FAILED! => {"changed": false, "cmd": "wp core language install de_CH '&&' wp core language install de_DE '&&' wp core language update", "failed": true, "rc": 2}

I got it working by switching from the command to the shell module:

- name: Install and update languages de_CH, de_DE
  shell: php ~/bin/wp core language install de_CH && php ~/bin/wp core language install de_DE && php ~/bin/wp core language update
  args:
    chdir: "{{ deploy_helper.new_release_path }}"

(Depending on the shell, one could omit the php ~/bin/ part and leave only wp core … – for this runs on a shared hosting.)