Roots Discourse

Best way to copy current release WPML .mo files over to new release when deploying

Hi there,

WPML has this great new feature where it saves your theme’s string translations to .mo files in the following location:

/srv/www/example.com/current/web/app/languages/wpml/sage-nl.mo

The problem is, the languages folder gets rebuild on every Trellis deploy with the composer install task. This results in missing string translations in my theme on the frontend after each deployment. When I login, and save a string translation in WPML, the .mo files are re-generated and my string translations are back on the frontend.

Since these translations are user generated and environment specific, I can’t put them in version control or keep them in sync locally.

I checked if there is a WPML filter available to change the default location where these .mo files are saved, so I can move them to the shared uploads folder, but there isn’t. There are also no WP-CLI commands available for WPML so I can add it to the playbook :roll_eyes:

So what would be the easiest fool proof way to copy these .mo files over from the current release folder to the new one? Which deploy_helper variables are available in the finalize-after or deploy_after deploy hooks?

Any help is appreciated!
Thanks!

Ok so I got a bot further. This is in my current finalize-after.yml:

- name: Check if WPML theme .mo files exist
  stat:
    path: "{{ item }}"
  register: wpml_theme_mo_paths
  with_items:
    - "{{ deploy_helper.previous_release_path }}/web/app/languages/wpml/sage-nl.mo"
    - "{{ deploy_helper.previous_release_path }}/web/app/languages/wpml/sage-de_DE.mo"

- name: Copy WPML theme .mo files to new release
  command: cp -rp {{ item.item }} {{ deploy_helper.new_release_path }}/web/app/languages/wpml/
  with_items: "{{ wpml_theme_mo_paths.results }}"
  when: item.stat.exists

I just can’t seem to get glob patterns working in the with_items list.
This doesn’t work:

with_items: "{{ deploy_helper.previous_release_path }}/web/app/languages/wpml/sage-*.mo"

Replacing it with with_fileglob also does not list any items:

with_fileglob:
  - "{{ deploy_helper.previous_release_path }}/web/app/languages/wpml/sage-*.mo"

Any ideas to make this work with a wildcard selector?
Thanks!

Ok so WPML suggests to change the WP_LANG_DIR constant.

If I do that in my config/application.php:

Config::define('WP_LANG_DIR', Config::get('WP_CONTENT_DIR') . '/uploads/languages');

and also change any dropin-paths in my composer.json:

"dropin-paths": {
  "web/app/uploads/languages/": ["vendor:koodimonni-language"],
  "web/app/uploads/languages/plugins/": ["vendor:koodimonni-plugin-language"],
  "web/app/uploads/languages/themes/": ["vendor:koodimonni-theme-language"]
}

And then update my .gitignore so it keeps the new languages folder in uploads:

web/app/uploads/*
!web/app/uploads/.gitkeep
!web/app/uploads/languages/.gitkeep

Could that cause any unforeseen problems when deploying?
Thanks!

2 Likes

You can also share your language folder using project_shared_children

Eg. wordpress_sites.yml

example.com
    ...
+  project_shared_children:
+    - path: web/app/uploads
+      src: uploads
+    - path: web/app/languages
+      src: languages
   ...

Or add to main.yml to enable on all sites

...
+  project_shared_children:
+    - path: web/app/uploads
+      src: uploads
+    - path: web/app/languages
+      src: languages
...
2 Likes

Thanks! I had no idea this variable existed!

This topic was automatically closed after 42 days. New replies are no longer allowed.