Python WorkBench or Macro translation Help request
Forum rules
and Helpful information
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!
Also, be nice to others! Read the FreeCAD code of conduct!
Python WorkBench or Macro translation Help request
Hi,
is there a way to provide translation text for an external python workbench or Macro?
Thanks
Maurice
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
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..
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
Hi Yorikyorik 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..
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
We should update the Localisation wiki pageyorik 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..
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
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
Re: Python WorkBench or Macro translation Help request
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:
normally i suppose it should be the same with pyside-lupdate...
pylupdate works like this:
Code: Select all
pylupdate /path/to/*.py -ts mytranslationfile.ts
Re: Python WorkBench or Macro translation Help request
thx @yorikyorik 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:normally i suppose it should be the same with pyside-lupdate...Code: Select all
pylupdate /path/to/*.py -ts mytranslationfile.ts
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...
thx @Kunda1
useful link
Re: Python WorkBench or Macro translation Help request
Here's my attempt to get easyw's Manipulator WB ready with lupdate translation infrastructure.
https://github.com/easyw/Manipulator/pull/11
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
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
Re: Python WorkBench or Macro translation Help request
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
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
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
Re: Python WorkBench or Macro translation Help request
Yorik wrote this a couple of months ago, Translating an external workbench. This is the forum thread, Translating external workbenches.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
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.
To support the documentation effort, and code development, your donation is appreciated: liberapay.com/FreeCAD.
Re: Python WorkBench or Macro translation Help request
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
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