Aventyret / solarplexus

Wordpress Block that is useful when building news sites
GNU General Public License v2.0
6 stars 1 forks source link

Fix translation issues #66

Closed fiwa closed 2 years ago

fiwa commented 2 years ago

Closes https://github.com/Aventyret/solarplexus/issues/60

Problem

When running wp i18n make-json separate files are created based on where the strings are extracted. The naming convention for each source file is {textdomain}-{locale}-{md5(source)}.json.

How WordPress looks for translation files:

  1. {textdomain}-{locale}-{script-handle}.json
  2. {textdomain}-{locale}-{source}.json
  3. {textdomain}-{locale}-{md5(source)}.json

"Source" in this case is build/index.js added with the handle solarplexus-script. This results in translations extracted from others sources not being loaded.

Example Translations extracted from src/components/dynamic-inspector-controls.js ends up in a file named {textdomain}-{locale}-{md5(src/components/dynamic-inspector-controls.js)}.json. The file is not loaded separately, resulting in the translations for the file not being loaded.

Solution

Translations needs to be extracted from "build/index.js" BUT that does not work on the minified version. Instead the translation scripts needs to be run in the yarn start state.

Steps to update translations

  1. Run yarn start to create a non-minified build/index.js.
  2. Run yarn translate to update splx.pot and existing splx-{locale}.po files.
  3. Translate new strings in splx-{locale}.po. This can be done through Poedit or directly in the file.
  4. Run yarn translate:compile to update splx-{locale}.mo and json files.

An alternative to the steps above could be to use po2json to convert the mo files to json. But currently the package generates warnings with Node 16.

perarnborg commented 2 years ago

@fiwa Perfect, it works!

Do you think it would be better to use po2json? Because we COULD bump down node to v14. If not I think this should be merged!

fiwa commented 2 years ago

@fiwa Perfect, it works!

Do you think it would be better to use po2json? Because we COULD bump down node to v14. If not I think this should be merged!

@perarnborg I think an extra step in the translation process is worth it in order to use Node 16.