Skip Navigation

This is the technical support forum for WPML - the multilingual WordPress plugin.

Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.

This topic contains 7 replies, has 2 voices.

Last updated by alexandreP-37 1 year, 12 months ago.

Assisted by: Bruno Kos.

Author Posts
February 15, 2023 at 11:38 am #13039507

alexandreP-37

We are using WordPress 6.1.1 with latest WPML Pro in a dockerfile on an infrastructure ran by Kubernetes.
Kubernetes creates several concurrent pods to serve WP to our audience from this dockerfile. This means that writing on the local file system is unreliable: files will only exist in one pod and not the others.
The issue we have is that translations seem to "disappear" and then reappear, as the .mo files are not consistent, although the string translation database is up to date and correct.
I know that I can manually force the mo file creation via the troubleshooting page but I want a way to automate it.
My question is this: is there a hook available that I could use to force the mo files generation, so that it is rebuilt when a pod is killed then created by Kubernetes?
Thank you!

February 15, 2023 at 11:42 am #13039519

alexandreP-37

I forgot one additional question. Since local file storage is not an option for us, we use Amazon S3 to store all our static assets and media files. Would it be possible to tell WPML to use our S3 instance to store the .mo files generated by WPML instead of writing locally?

February 15, 2023 at 12:36 pm #13040047

Bruno Kos
Supporter

Languages: English (English ) German (Deutsch ) French (Français )

Timezone: Europe/Zagreb (GMT+01:00)

Hi,

Thank you for contacting WPML support!

Can you check this answer (and a thread as a whole)?
https://wpml.org/forums/topic/store-string-translations-not-in-an-mo-file/#post-12866519

Regards,
Bruno Kos

February 15, 2023 at 1:39 pm #13040499

alexandreP-37

I was the person initiating that thread 🙂

I tried setting the constant mentioned in that thread, but the issue keeps repeating so that solution did not work for me, hence this new question. Can you tell me if there is a hook I could use to trigger the mo file generation, so as to automate it ?

February 15, 2023 at 1:52 pm #13040595

Bruno Kos
Supporter

Languages: English (English ) German (Deutsch ) French (Français )

Timezone: Europe/Zagreb (GMT+01:00)

Hi,

I apologize for missing that. There is an internal plugin our developers are using for codeception tests, but we can't share it with our clients.

It goes something like:

$> wp shell  
wp> (new WPML\ST\MO\Generate\Process\ProcessFactory() )->create()->runAll();
=> NULL
wp> exit

Can you try that, does it help?

Regards,
Bruno Kos

February 15, 2023 at 3:02 pm #13041743

alexandreP-37

Yes it does! When i launched the command, it created the .mo files in the language/wpml folder.

But launching it via wp-cli is going to be complicated. Can you check if there is a way to trigger this function from the php codebase, to the "init" hook for example?

February 15, 2023 at 3:38 pm #13042061

Bruno Kos
Supporter

Languages: English (English ) German (Deutsch ) French (Français )

Timezone: Europe/Zagreb (GMT+01:00)

Hi,

Such case goes within custom work given that such functionality is not natively supported in WPML through official hooks, so you can consult our https://wpml.org/contractors/ for help if needed.

However an idea can be also something like this:

- Create a php file in WP root with this in it, call it sync-mo.php:

<?php
require "wp-load.php";

(new WPML\ST\MO\Generate\Process\ProcessFactory() )->create()->runAll();

- Then call it with "php sync-mo.php"

Maybe 'init' would work, but we advise against calling that on every 'init', better to use cron.

Regards,
Bruno Kos

February 15, 2023 at 4:49 pm #13042707

alexandreP-37

I followed your advise and use wp-cron to trigger the call.

My issue is resolved now. Thank you!