-
-
Notifications
You must be signed in to change notification settings - Fork 56
Cura plugin translation guide
Vasily Elkin edited this page Jun 24, 2022
·
2 revisions
- Write your code as it was described here;
- Create directory
<your plugin root directory>/i18n
; - 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; - Add this code to every .py file that needs to be translated:
catalog = i18nCatalog("<your translation name>")
; - You can check which .py executes at first with this code:
if catalog.hasTranslationLoaded():
Logger.log("i", "Plugin translation loaded!")
- To translate .qml files you will need to add
UM.I18nCatalog { id: catalog; name:"<your translation name>" }
; - Now you will need to generate
<your translation name>.pot
file. You will need to install gettext package. Than open terminal and go toyour 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)
andxgettext --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; - Go to
<your plugin root directory>/i18n
; - Create new directory
<your plugin root directory>/i18n/<new locale>
. Locales should be named as Cura ones; - 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; - Now you will need an linguist app such as Poedit. Open .po in it and translate everything you need;
- Save .po and create /i18n//LC_MESSAGES directory;
- Execute
msgfmt <your translation name>.po -o LC_MESSAGES/<your translation name>.mo
; - Now it should work just fine.
You can figure out more by reading this: MKS WiFi Plugin Translation guide and This.