Page 1 of 1

Python WorkBench or Macro translation Help request

Posted: Fri Nov 03, 2017 11:30 am
by easyw-fc
Hi,
is there a way to provide translation text for an external python workbench or Macro?

Thanks

Maurice

Re: Python WorkBench or Macro translation Help request

Posted: Fri Nov 03, 2017 2:25 pm
by yorik
Yes it's possible, it's easy to add the necessary code, but you have to take care of all the management of translations, that's the biggest hassle. Basically:

1) Where you display a string in your code, instead of displaying "my text", you display translate("context","my text"). context can be anything you choose, it's for the translator to know where this string comes from.
2) you define a translate(context, text) function in your code. Check in Arch or Path workbenches, it is generally defined at the top of the files
3) you run the pylupdate utility on your code. This will crawl through your code and gather all the strings that are inside a translate() function into a .ts file
4) you translate that .ts file yourself with Qtranslator, or upload it to some crowd-translating site such as crowdin (there are others that support Qt's .ts files too)
5) when you have some translations ready, you convert the .ts files into .qm files with the lrelease utility
6) you place the .qm files in some folder in your module
7) you create a .qrc file that contains links to all your .qm files (again check in Arch or Draft or Path how it's done there)
8) you create a _rc.py resource from that qrc file with the pyrcc utility
9) in your module code, you import your new _rc.py everywhere before using the translate function.

That's basically it.. As you see there is a big hassle of managing and updating the translations. However this can be automated quite a lot, that's what we do in freecad itself..

Re: Python WorkBench or Macro translation Help request

Posted: Fri Nov 03, 2017 3:02 pm
by easyw-fc
yorik wrote: Fri Nov 03, 2017 2:25 pm Yes it's possible, it's easy to add the necessary code, but you have to take care of all the management of translations, that's the biggest hassle. Basically:

1) Where you display a string in your code, instead of displaying "my text", you display translate("context","my text"). context can be anything you choose, it's for the translator to know where this string comes from.
2) you define a translate(context, text) function in your code. Check in Arch or Path workbenches, it is generally defined at the top of the files
3) you run the pylupdate utility on your code. This will crawl through your code and gather all the strings that are inside a translate() function into a .ts file
4) you translate that .ts file yourself with Qtranslator, or upload it to some crowd-translating site such as crowdin (there are others that support Qt's .ts files too)
5) when you have some translations ready, you convert the .ts files into .qm files with the lrelease utility
6) you place the .qm files in some folder in your module
7) you create a .qrc file that contains links to all your .qm files (again check in Arch or Draft or Path how it's done there)
8) you create a _rc.py resource from that qrc file with the pyrcc utility
9) in your module code, you import your new _rc.py everywhere before using the translate function.

That's basically it.. As you see there is a big hassle of managing and updating the translations. However this can be automated quite a lot, that's what we do in freecad itself..
Hi Yorik
I went through point 1) and 2) ...
then at point 3) I tried to use:
'pyside-lupdate.exe myMacro.py' or 'pyside-lupdate.exe myMacro.ui'
and I get this error
pyside-lupdate warning: File 'myMacro.py' does not look like a project file (the same error for myMacro.ui)
Is that fine to use those files?

Also I miss in point 7) how to create a qrc from qm files

P.S. I'm on Win10 and I use the tools from FreeCAD\bin\Lib\site-packages\PySide that I installed by using pip install
I have these tools available:
1) pyside-lupdate.exe
2) pyside-rcc.exe

Thanks again
Maurice

Re: Python WorkBench or Macro translation Help request

Posted: Fri Nov 03, 2017 4:04 pm
by Kunda1
yorik wrote: Fri Nov 03, 2017 2:25 pm Yes it's possible, it's easy to add the necessary code, but you have to take care of all the management of translations, that's the biggest hassle. Basically:

1) Where you display a string in your code, instead of displaying "my text", you display translate("context","my text"). context can be anything you choose, it's for the translator to know where this string comes from.
2) you define a translate(context, text) function in your code. Check in Arch or Path workbenches, it is generally defined at the top of the files
3) you run the pylupdate utility on your code. This will crawl through your code and gather all the strings that are inside a translate() function into a .ts file
4) you translate that .ts file yourself with Qtranslator, or upload it to some crowd-translating site such as crowdin (there are others that support Qt's .ts files too)
5) when you have some translations ready, you convert the .ts files into .qm files with the lrelease utility
6) you place the .qm files in some folder in your module
7) you create a .qrc file that contains links to all your .qm files (again check in Arch or Draft or Path how it's done there)
8) you create a _rc.py resource from that qrc file with the pyrcc utility
9) in your module code, you import your new _rc.py everywhere before using the translate function.

That's basically it.. As you see there is a big hassle of managing and updating the translations. However this can be automated quite a lot, that's what we do in freecad itself..
We should update the Localisation wiki page

Re: Python WorkBench or Macro translation Help request

Posted: Mon Nov 06, 2017 8:34 pm
by yorik
You can check src/Tools/updatets.py and src/Tools/updatefromcrowdin.py, , that's the auto scripts we use in FreeCAD source code, they basically do most of the procedure above.
pylupdate works like this:

Code: Select all

pylupdate /path/to/*.py -ts mytranslationfile.ts
normally i suppose it should be the same with pyside-lupdate...

Re: Python WorkBench or Macro translation Help request

Posted: Mon Nov 06, 2017 9:24 pm
by easyw-fc
yorik wrote: Mon Nov 06, 2017 8:34 pm You can check src/Tools/updatets.py and src/Tools/updatefromcrowdin.py, , that's the auto scripts we use in FreeCAD source code, they basically do most of the procedure above.
pylupdate works like this:

Code: Select all

pylupdate /path/to/*.py -ts mytranslationfile.ts
normally i suppose it should be the same with pyside-lupdate...
thx @yorik
I think I could find the needed exe files in the latest LibPacks here
https://github.com/sgrogan/FreeCAD/rele ... 7-med-test
I will have a look at...
Kunda1 wrote: Fri Nov 03, 2017 4:04 pm We should update the Localisation wiki page
thx @Kunda1
useful link :D

Re: Python WorkBench or Macro translation Help request

Posted: Wed Sep 26, 2018 10:55 pm
by Kunda1
Here's my attempt to get easyw's Manipulator WB ready with lupdate translation infrastructure.
https://github.com/easyw/Manipulator/pull/11

Re: Python WorkBench or Macro translation Help request

Posted: Fri Sep 20, 2019 12:03 pm
by Kunda1
Opened 2 tickets related to this:
issue #4033 - Translations of External workbenches need to be incorporated in to Crowdin (import/export) translation scripts
issue #4138 - Step-by-Step tutorial for External workbench devs to translate their workbench

Re: Python WorkBench or Macro translation Help request

Posted: Fri Sep 20, 2019 2:57 pm
by vocx
Kunda1 wrote: Fri Sep 20, 2019 12:03 pm Opened 2 tickets related to this:
issue #4033 - Translations of External workbenches need to be incorporated in to Crowdin (import/export) translation scripts
issue #4138 - Step-by-Step tutorial for External workbench devs to translate their workbench
Yorik wrote this a couple of months ago, Translating an external workbench. This is the forum thread, Translating external workbenches.

Re: Python WorkBench or Macro translation Help request

Posted: Fri Sep 20, 2019 6:50 pm
by Kunda1
vocx wrote: Fri Sep 20, 2019 2:57 pm Yorik wrote this a couple of months ago, Translating an external workbench. This is the forum thread, Translating external workbenches.
@vocx, nice! Yikes, I also contributed to that wiki page, hah!
Blame it on my A.D.D., Baby! (clip)