4

I'm trying to make 'wp_set_script_translations' work with theme in conjunction with wpml.

I had implemented all the recommendations from Wordpress Codex. WPML plugin generates file in format "locale-domain-handle.json" in "\wp-content\languages\wpml" folder. But file generates without translations and with wrong domain name "messages" instead domain that I specified. Also I checked WPML String Translation files and it seems that wrong json generates by JED function that always sets "message" domain and ignores customer domain name.

{
  "translation-revision-date": "2019-04-23 08:33:37+0000",
  "generator": "WPML String Translation 2.10.2",
  "domain": "messages",
  "locale_data": {
    "messages": {
      "": {
        "domain": "messages",
        "plural-forms": "nplurals=2; plural=n != 1;",
        "lang": "fr_FR"
      }
    }
  }
}

I would like to see the translations with right domain name in the file or alternative and automated method without manual generation of translation files.

Yura Kosyak
  • 401
  • 3
  • 16
  • It seems that using `messages` as text domain is correct. Maybe you are experiencing some issues with the JSON file MD5 hash. Have a look here: https://wordpress.stackexchange.com/a/415545/231798 – xonya Apr 22 '23 at 20:55

1 Answers1

0

Translation has finally been properly developed and documented: https://developer.wordpress.org/block-editor/developers/internationalization/

Basically, you need to:

  1. Use the wp-i18n package to define which are the strings in your project to be translatable.
  2. Compile your code (wp i18n make-pot will search for translation strings in your compiled code, not in your source).
  3. Use the WP-CLI (wp i18n make-pot) to create a .pot file, just like we've always used with WP themes and plugins.
  4. Generate a .po file based on our previously created .pot and translate its content.
  5. Use the WP-CLI again (wp i18n make-json) to convert our .po file to the JSON format needed.
  6. Use the wp_set_script_translations PHP function to load the translation files.

Hope this helps someone out there ;)