Skip to content

Cura plugin translation guide

Vasily Elkin edited this page Jun 24, 2022 · 2 revisions

Making your Cura Plugin translatable

  1. Write your code as it was described here;
  2. Create directory <your plugin root directory>/i18n;
  3. Add to your plugin .py file that executes at first this code: Resources.addSearchPath(os.path.join(os.path.abspath(os.path.dirname(__file__)))) This will automatically add your i18n directory to the list of directories where Uranium searches translation files;
  4. Add this code to every .py file that needs to be translated: catalog = i18nCatalog("<your translation name>");
  5. You can check which .py executes at first with this code: if catalog.hasTranslationLoaded(): Logger.log("i", "Plugin translation loaded!")
  6. To translate .qml files you will need to add UM.I18nCatalog { id: catalog; name:"<your translation name>" };
  7. Now you will need to generate <your translation name>.pot file. You will need to install gettext package. Than open terminal and go to your plugin root directory. Execute there: xgettext --package-name='<your plugin name>' --from-code=UTF-8 --language=python -ki18n:1 -ki18nc:1c,2 -ki18np:1,2 -ki18ncp:1c,2,3 -o i18n/<your translation name>.pot $(find -L <path to .py files> -name \*.py) and xgettext --package-name='<your plugin name>' --from-code=UTF-8 --join-existing --language=javascript -ki18n:1 -ki18nc:1c,2 -ki18np:1,2 -ki18ncp:1c,2,3 -o i18n/<your translation name>.pot $(find -L <path to .qml files> -name \*.qml). This will make translation template for your plugin;
  8. Go to <your plugin root directory>/i18n;
  9. Create new directory <your plugin root directory>/i18n/<new locale>. Locales should be named as Cura ones;
  10. Execute msginit --input=<your translation name>.pot --locale=<new locale> --output=<new locale>/<your translation name>.po this will make a .po to the new locale;
  11. Now you will need an linguist app such as Poedit. Open .po in it and translate everything you need;
  12. Save .po and create /i18n//LC_MESSAGES directory;
  13. Execute msgfmt <your translation name>.po -o LC_MESSAGES/<your translation name>.mo;
  14. Now it should work just fine.

You can figure out more by reading this: MKS WiFi Plugin Translation guide and This.

Clone this wiki locally