Python WorkBench or Macro translation Help request

Post here for help on using FreeCAD's graphical user interface (GUI).
Forum rules
and Helpful information
IMPORTANT: Please click here and read this first, before asking for help

Also, be nice to others! Read the FreeCAD code of conduct!
Post Reply
User avatar
easyw-fc
Veteran
Posts: 3629
Joined: Thu Jul 09, 2015 9:34 am

Python WorkBench or Macro translation Help request

Post by easyw-fc »

Hi,
is there a way to provide translation text for an external python workbench or Macro?

Thanks

Maurice
User avatar
yorik
Founder
Posts: 13640
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: Python WorkBench or Macro translation Help request

Post 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..
User avatar
easyw-fc
Veteran
Posts: 3629
Joined: Thu Jul 09, 2015 9:34 am

Re: Python WorkBench or Macro translation Help request

Post 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
User avatar
Kunda1
Veteran
Posts: 13434
Joined: Thu Jan 05, 2017 9:03 pm

Re: Python WorkBench or Macro translation Help request

Post 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
Alone you go faster. Together we go farther
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
'good first issues' | Open TODOs and FIXMEs | How to Help FreeCAD | How to report Bugs
User avatar
yorik
Founder
Posts: 13640
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: Python WorkBench or Macro translation Help request

Post 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...
User avatar
easyw-fc
Veteran
Posts: 3629
Joined: Thu Jul 09, 2015 9:34 am

Re: Python WorkBench or Macro translation Help request

Post 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
User avatar
Kunda1
Veteran
Posts: 13434
Joined: Thu Jan 05, 2017 9:03 pm

Re: Python WorkBench or Macro translation Help request

Post by Kunda1 »

Here's my attempt to get easyw's Manipulator WB ready with lupdate translation infrastructure.
https://github.com/easyw/Manipulator/pull/11
Alone you go faster. Together we go farther
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
'good first issues' | Open TODOs and FIXMEs | How to Help FreeCAD | How to report Bugs
User avatar
Kunda1
Veteran
Posts: 13434
Joined: Thu Jan 05, 2017 9:03 pm

Re: Python WorkBench or Macro translation Help request

Post 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
Alone you go faster. Together we go farther
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
'good first issues' | Open TODOs and FIXMEs | How to Help FreeCAD | How to report Bugs
vocx
Veteran
Posts: 5197
Joined: Thu Oct 18, 2018 9:18 pm

Re: Python WorkBench or Macro translation Help request

Post 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.
Always add the important information to your posts if you need help. Also see Tutorials and Video tutorials.
To support the documentation effort, and code development, your donation is appreciated: liberapay.com/FreeCAD.
User avatar
Kunda1
Veteran
Posts: 13434
Joined: Thu Jan 05, 2017 9:03 pm

Re: Python WorkBench or Macro translation Help request

Post 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)
Alone you go faster. Together we go farther
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
'good first issues' | Open TODOs and FIXMEs | How to Help FreeCAD | How to report Bugs
Post Reply