Small script for translator (for local work)

Info about new community or project announcements, implemented features, classes, modules or APIs. Might get technical!
PLEASE DO NOT POST HELP REQUESTS OR OTHER DISCUSSIONS HERE!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
User avatar
Kuzma30
Posts: 163
Joined: Wed Oct 24, 2018 11:50 am
Location: Ukraine

Small script for translator (for local work)

Post by Kuzma30 »

As described in the wiki, there are scripts to work with translation files, upload them to the server, and update the translations in a branch. They work great, but there is one problem (for me). They need admin rights of the crowdin.com server to work.
As a small translator, I had a problem with the update of the translation in the freecad program. I like to see and edit translations as necessary, depending on how they look in the program itself. My language (Ukrainian) is context sensitive.

It's all lyrics. So I'll get down to business.
A script was written that updates the translation files in the program. The source file is the downloaded archive from the server. It's look like FreeCAD $Your_Language_CODE.zip

There are 3 variables in the script, 2 language codes, with capital and small letters, and the location of the directory with FreeCAD source. They can be changed according to your needs.

I am not a great programmer and not a great translator (I can write with errors in English), but the script seems to work. Use at your own risk.

Code: Select all

# define language code here
lang_Code="uk"
lang_Code_Upper_Case="UK"
FreeCAD="FreeCAD"

#Make directory for extracted files
mkdir -p FreeCAD_$lang_Code_Upper_Case

#Unzip archive to directory
unzip "FreeCAD ($lang_Code).zip" -d FreeCAD_$lang_Code_Upper_Case

echo "Preparing files"
#rename all files in directory
cd FreeCAD_$lang_Code_Upper_Case
rename 's/.ts$//' *.ts
ls | xargs -I {} mv {} {}_$lang_Code.ts
rm homepage.po_$lang_Code.ts

echo "Start creating qm files"
#Create qm files for all ts
lrelease *.ts
#Update ts in FreeCAD tree
echo "Copying translation files in defined place"
cp AddonManager_$lang_Code.* ~/$FreeCAD/src/Mod/AddonManager/Resources/translations/

cp Arch_$lang_Code.* ~/$FreeCAD/src/Mod/Arch/Resources/translations

cp Assembly_$lang_Code.* ~/$FreeCAD/src/Mod/Assembly/Gui/Resources/translations

#Complete_$lang_Code.ts
#draft_$lang_Code.ts
cp Drawing_$lang_Code.* ~/$FreeCAD/src/Mod/Drawing/Gui/Resources/translations

cp Fem_$lang_Code.* ~/$FreeCAD/src/Mod/Fem/Gui/Resources/translations

cp FreeCAD_$lang_Code.* ~/$FreeCAD/src/Gui/Language

cp Image_$lang_Code.* ~/$FreeCAD/src/Mod/Image/Gui/Resources/translations

cp MeshPart_$lang_Code.* ~/$FreeCAD/src/Mod/MeshPart/Gui/Resources/translations

cp Mesh_$lang_Code.* ~/$FreeCAD/src/Mod/Mesh/Gui/Resources/translations

cp OpenSCAD_$lang_Code.* ~/$FreeCAD/src/Mod/OpenSCAD/Resources/translations

cp PartDesign_$lang_Code.* ~/$FreeCAD/src/Mod/PartDesign/Gui/Resources/translations

cp Part_$lang_Code.* ~/$FreeCAD/src/Mod/Part/Gui/Resources/translations

cp Path_$lang_Code.* ~/$FreeCAD/src/Mod/Path/Gui/Resources/translations

#Plot_$lang_Code.ts
cp Points_$lang_Code.* ~/$FreeCAD/src/Mod/Points/Gui/Resources/translations

cp Raytracing_$lang_Code.* ~/$FreeCAD/src/Mod/Raytracing/Gui/Resources/translations

cp ReverseEngineering_$lang_Code.* ~/$FreeCAD/src/Mod/ReverseEngineering/Gui/Resources/translations

cp Robot_$lang_Code.* ~/$FreeCAD/src/Mod/Robot/Gui/Resources/translations

#Ship_$lang_Code.ts
cp Sketcher_$lang_Code.* ~/$FreeCAD/src/Mod/Sketcher/Gui/Resources/translations

cp Spreadsheet_$lang_Code.* ~/$FreeCAD/src/Mod/Spreadsheet/Gui/Resources/translations

cp StartPage_$lang_Code.* ~/$FreeCAD/src/Mod/Start/Gui/Resources/translations

cp TechDraw_$lang_Code.ts ~/$FreeCAD/src/Mod/TechDraw/Gui/Resources/translations

cp Test_$lang_Code.ts ~/$FreeCAD/src/Mod/Test/Gui/Resources/translations

cp Tux_$lang_Code.ts ~/$FreeCAD/src/Mod/Tux/Resources/translations

cp Web_$lang_Code.ts ~/$FreeCAD/src/Mod/Web/Gui/Resources/translations

echo "Finish. Now you may re-build FreeCAD to see updated translation for $lang_Code_Upper_Case language"

To rerun script you need empty temporary directory FreeCAD_$lang_Code_Upper_Case. I don't found where Complete.ts, draft.ts, Ship.ts Plot.ts is placed and ignore it.
Attachments
Знімок екрана з 2022-04-16 19-32-09.png
Знімок екрана з 2022-04-16 19-32-09.png (65.79 KiB) Viewed 2127 times
RealThunder's A3 Wiki translation, join the project https://crowdin.com/project/freecad-asm3-wiki
User avatar
Kunda1
Veteran
Posts: 13434
Joined: Thu Jan 05, 2017 9:03 pm

Re: Small script for translator (for local work)

Post by Kunda1 »

Great stuff. Can you open an issue and mention this script on https://github.com/FreeCAD/FreeCAD-translations/issues ?
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
Kuzma30
Posts: 163
Joined: Wed Oct 24, 2018 11:50 am
Location: Ukraine

Re: Small script for translator (for local work)

Post by Kuzma30 »

Kunda1 wrote: Sat Apr 16, 2022 5:42 pm Great stuff. Can you open an issue and mention this script on https://github.com/FreeCAD/FreeCAD-translations/issues ?
https://github.com/FreeCAD/FreeCAD-tran ... issues/110 Done.
RealThunder's A3 Wiki translation, join the project https://crowdin.com/project/freecad-asm3-wiki
User avatar
kaktus
Veteran
Posts: 1174
Joined: Sun Aug 11, 2019 11:59 am
Location: opolskie
Contact:

Re: Small script for translator (for local work)

Post by kaktus »

:mrgreen:

I can congratulate you on the good work.

Today the FreeCAD-translations Testing section has been completed for translators testing in their environment.
There is a good dose of useful information there. ;)
Twórca polskiej wersji Wiki dla FreeCAD, współwórca polskiej wersji GUI.
"Cierpliwym być musisz, by wiedzę zgłębiać tajemną, gdyż ciemna strona mocy niszczącą i silną jest".
User avatar
Kuzma30
Posts: 163
Joined: Wed Oct 24, 2018 11:50 am
Location: Ukraine

Re: Small script for translator (for local work)

Post by Kuzma30 »

kaktus wrote: Sat Apr 16, 2022 7:01 pm :mrgreen:

I can congratulate you on the good work.

Today the FreeCAD-translations Testing section has been completed for translators testing in their environment.
There is a good dose of useful information there. ;)
Thanks.
Thoughts are material:) I honestly haven't seen your script implementation, it's more elegant.
RealThunder's A3 Wiki translation, join the project https://crowdin.com/project/freecad-asm3-wiki
User avatar
kaktus
Veteran
Posts: 1174
Joined: Sun Aug 11, 2019 11:59 am
Location: opolskie
Contact:

Re: Small script for translator (for local work)

Post by kaktus »

:mrgreen:

Your skrpt overwrites the translation files supplied with your FreeCAD installation.
This is not a good solution, but it works. :roll:

FreeCAD has a place in its directory structure for alternative translation files. It is worth using it.

First-hand information.
https://forum.freecadweb.org/viewtopic. ... 64#p533464

You may possibly find the whole topic interesting. The link will take you directly to wmayer's developer post.
;)
This also works for the operating system coming from Redmond. :lol:

The instructions on GitHub to which I posted a link earlier contain all this information.
My warmest regards to you :D
Twórca polskiej wersji Wiki dla FreeCAD, współwórca polskiej wersji GUI.
"Cierpliwym być musisz, by wiedzę zgłębiać tajemną, gdyż ciemna strona mocy niszczącą i silną jest".
User avatar
Kuzma30
Posts: 163
Joined: Wed Oct 24, 2018 11:50 am
Location: Ukraine

Re: Small script for translator (for local work)

Post by Kuzma30 »

Many copy/paste and I make another script (for separately downloaded files). It also rewrite ts files in FreeCAD source.

Code: Select all

# define language code here
lang_Code="uk"
lang_Code_Upper_Case="UK"
FreeCAD="FreeCAD"

case "$1" in
    "AddonManager.ts") 
	echo " AddonManager.ts"
	lrelease  AddonManager.ts
	cp AddonManager.ts ~/$FreeCAD/src/Mod/AddonManager/Resources/translations/AddonManager_$lang_Code.ts
	cp AddonManager.qm ~/$FreeCAD/src/Mod/AddonManager/Resources/translations/AddonManager_$lang_Code.qm
	echo "Finish. Now you may re-build FreeCAD to see updated translation for AddonManager_$lang_Code_Upper_Case";;
    "Arch.ts")
	echo " Arch.ts"
	lrelease  Arch.ts
	cp Arch.ts ~/$FreeCAD/src/Mod/Arch/Resources/translations/Arch_$lang_Code.ts
	cp Arch.qm ~/$FreeCAD/src/Mod/Arch/Resources/translations/Arch_$lang_Code.qm
	echo "Finish. Now you may re-build FreeCAD to see updated translation for Arch_$lang_Code_Upper_Case";;
    "Assembly.ts")
	echo " Assembly.ts"
	lrelease  Assembly.ts
	cp Assembly.ts ~/$FreeCAD/src/Mod/Assembly/Gui/Resources/translations/Assembly_$lang_Code.ts
	cp Assembly.qm ~/$FreeCAD/src/Mod/Assembly/Gui/Resources/translations/Assembly_$lang_Code.qm
	echo "Finish. Now you may re-build FreeCAD to see updated translation for Assembly_$lang_Code_Upper_Case";;
    "Complete.ts")
	echo " Complete.ts"
	lrelease  Complete.ts
	cp Complete.ts Complete_$lang_Code.ts
	cp Complete.qm Complete_$lang_Code.qm
	echo "Unknow location for files. Place it yourself";; 
    "draft.ts")
	echo "draft.ts"
	lrelease  draft.ts
	cp draft.ts ~/$FreeCAD/src/Mod/Draft/Resources/translations/Draft_$lang_Code.ts
	cp draft.qm ~/$FreeCAD/src/Mod/Draft/Resources/translations/Draft_$lang_Code.qm
	echo "Finish. Now you may re-build FreeCAD to see updated translation for Draft_$lang_Code_Upper_Case";;
    "Drawing.ts")
	echo "Drawing.ts"
	lrelease  Drawing.ts
	cp Drawing.ts ~/$FreeCAD/src/Mod/Drawing/Gui/Resources/translations/Drawing_$lang_Code.ts
	cp Drawing.qm ~/$FreeCAD/src/Mod/Drawing/Gui/Resources/translations/Drawing_$lang_Code.qm
	echo "Finish. Now you may re-build FreeCAD to see updated translation for Drawing_$lang_Code_Upper_Case";;
    "Fem.ts")
	echo "Fem.ts"	
	lrelease  Fem.ts
	cp Fem.ts ~/$FreeCAD/src/Mod/Fem/Gui/Resources/translations/Fem_$lang_Code.ts
	cp Fem.qm ~/$FreeCAD/src/Mod/Fem/Gui/Resources/translations/Fem_$lang_Code.qm
	echo "Finish. Now you may re-build FreeCAD to see updated translation for Fem_$lang_Code_Upper_Case";;
    "FreeCAD.ts")
	echo "FreeCAD.ts"
	lrelease  FreeCAD.ts
	cp FreeCAD.ts ~/$FreeCAD/src/Gui/Language/FreeCAD_$lang_Code.ts
	cp FreeCAD.qm ~/$FreeCAD/src/Gui/Language/FreeCAD_$lang_Code.qm
	echo "Finish. Now you may re-build FreeCAD to see updated translation for FreeCAD_$lang_Code_Upper_Case";;
    "Image.ts")
	echo " Image.ts"
	lrelease  Image.ts
	cp Image.ts ~/$FreeCAD/src/Mod/Image/Gui/Resources/translations/Image_$lang_Code.ts
	cp Image.qm ~/$FreeCAD/src/Mod/Image/Gui/Resources/translations/Image_$lang_Code.qm
	echo "Finish. Now you may re-build FreeCAD to see updated translation for Image_$lang_Code_Upper_Case";;
    "MeshPart.ts")
	echo " MeshPart.ts"
	lrelease  MeshPart.ts
	cp MeshPart.ts ~/$FreeCAD/src/Mod/MeshPart/Gui/Resources/translations/MeshPart_$lang_Code.ts
	cp MeshPart.qm ~/$FreeCAD/src/Mod/MeshPart/Gui/Resources/translations/MeshPart_$lang_Code.qm
	echo "Finish. Now you may re-build FreeCAD to see updated translation for MeshPart_$lang_Code_Upper_Case";;
    "Mesh.ts")
	echo "Mesh.ts"
	lrelease  Mesh.ts
	cp Mesh.ts ~/$FreeCAD/src/Mod/Mesh/Gui/Resources/translations/Mesh_$lang_Code.ts
	cp Mesh.qm ~/$FreeCAD/src/Mod/Mesh/Gui/Resources/translations/Mesh_$lang_Code.qm
	echo "Finish. Now you may re-build FreeCAD to see updated translation for Mesh_$lang_Code_Upper_Case";;
    "OpenSCAD.ts")
	echo "OpenSCAD.ts"
	lrelease  OpenSCAD.ts
	cp OpenSCAD.ts ~/$FreeCAD/src/Mod/OpenSCAD/Resources/translations/OpenSCAD_$lang_Code.ts
	cp OpenSCAD.qm ~/$FreeCAD/src/Mod/OpenSCAD/Resources/translations/OpenSCAD_$lang_Code.qm
	echo "Finish. Now you may re-build FreeCAD to see updated translation for OpenSCAD_$lang_Code_Upper_Case";;
    "PartDesign.ts")
	echo " PartDesign.ts"
	lrelease  PartDesign.ts
	cp PartDesign.ts ~/$FreeCAD/src/Mod/PartDesign/Gui/Resources/translations/PartDesign_$lang_Code.ts
	cp PartDesign.qm ~/$FreeCAD/src/Mod/PartDesign/Gui/Resources/translations/PartDesign_$lang_Code.qm
	echo "Finish. Now you may re-build FreeCAD to see updated translation for PartDesign_$lang_Code_Upper_Case";;
    "Part.ts")
	echo "Part.ts"
	lrelease  Part.ts
	cp Part.ts ~/$FreeCAD/src/Mod/Part/Gui/Resources/translations/Part_$lang_Code.ts
	cp Part.qm ~/$FreeCAD/src/Mod/Part/Gui/Resources/translations/Part_$lang_Code.qm
	echo "Finish. Now you may re-build FreeCAD to see updated translation for Part_$lang_Code_Upper_Case";;
    "Path.ts")
	echo " Path.ts"
	lrelease  Path.ts
	cp Path.ts ~/$FreeCAD/src/Mod/Path/Gui/Resources/translations/Path_$lang_Code.ts
	cp Path.qm ~/$FreeCAD/src/Mod/Path/Gui/Resources/translations/Path_$lang_Code.qm
	echo "Finish. Now you may re-build FreeCAD to see updated translation for Path_$lang_Code_Upper_Case";;    
    "Plot.ts")
	echo "Plot.ts"
	lrelease  Plot.ts
	cp Plot.ts Plot_$lang_Code.ts
	cp Plot.qm Plot_$lang_Code.qm
	echo "Unknow location for files. Place it yourself";; 
    "Points.ts")
	echo "Points.ts"
	lrelease  Points.ts
	cp Points.ts ~/$FreeCAD/src/Mod/Points/Gui/Resources/translations/Points_$lang_Code.ts
	cp Points.qm ~/$FreeCAD/src/Mod/Points/Gui/Resources/translations/Points_$lang_Code.qm
	echo "Finish. Now you may re-build FreeCAD to see updated translation for Points_$lang_Code_Upper_Case";;    
    "Raytracing.ts")
	echo " Raytracing.ts"
	lrelease  Raytracing.ts
	cp Raytracing.ts ~/$FreeCAD/src/Mod/Raytracing/Gui/Resources/translations/Raytracing_$lang_Code.ts
	cp Raytracing.qm ~/$FreeCAD/src/Mod/Raytracing/Gui/Resources/translations/Raytracing_$lang_Code.qm
	echo "Finish. Now you may re-build FreeCAD to see updated translation for Raytracing_$lang_Code_Upper_Case";; 
    "ReverseEngineering.ts")
	echo " ReverseEngineering.ts"
	lrelease  ReverseEngineering.ts
	cp ReverseEngineering.ts ~/$FreeCAD/src/Mod/ReverseEngineering/Gui/Resources/translations/ReverseEngineering_$lang_Code.ts
	cp ReverseEngineering.qm ~/$FreeCAD/src/Mod/ReverseEngineering/Gui/Resources/translations/ReverseEngineering_$lang_Code.qm
	echo "Finish. Now you may re-build FreeCAD to see updated translation for ReverseEngineering_$lang_Code_Upper_Case";; 
    "Robot.ts")
	echo	"Robot.ts"
	lrelease  Robot.ts
	cp Robot.ts ~/$FreeCAD/src/Mod/Robot/Gui/Resources/translations/Robot_$lang_Code.ts
	cp Robot.qm ~/$FreeCAD/src/Mod/Robot/Gui/Resources/translations/Robot_$lang_Code.qm
	echo "Finish. Now you may re-build FreeCAD to see updated translation for Robot_$lang_Code_Upper_Case";; 
    "Ship.ts")
	echo "Ship.ts"
	lrelease  Ship.ts
	cp Ship.ts Ship_$lang_Code.ts
	cp Ship.qm Ship_$lang_Code.qm
	echo "Unknow location for files. Place it yourself";; 
    "Sketcher.ts")
	echo " Sketcher.ts"
	lrelease  Sketcher.ts
	cp Sketcher.ts ~/$FreeCAD/src/Mod/Sketcher/Gui/Resources/translations/Sketcher_$lang_Code.ts
	cp Sketcher.qm ~/$FreeCAD/src/Mod/Sketcher/Gui/Resources/translations/Sketcher_$lang_Code.qm
	echo "Finish. Now you may re-build FreeCAD to see updated translation for Sketcher_$lang_Code_Upper_Case";; 
    "Spreadsheet.ts")
	echo " Spreadsheet.ts"
	lrelease  Spreadsheet.ts
	cp Spreadsheet.ts ~/$FreeCAD/src/Mod/Spreadsheet/Gui/Resources/translations/Spreadsheet_$lang_Code.ts
	cp Spreadsheet.qm ~/$FreeCAD/src/Mod/Spreadsheet/Gui/Resources/translations/Spreadsheet_$lang_Code.qm
	echo "Finish. Now you may re-build FreeCAD to see updated translation for Spreadsheet_$lang_Code_Upper_Case";; 
    "StartPage.ts")
	echo "StartPage.ts"
	lrelease  StartPage.ts
	cp StartPage.ts ~/$FreeCAD/src/Mod/Start/Gui/Resources/translations/StartPage_$lang_Code.ts
	cp StartPage.qm ~/$FreeCAD/src/Mod/Start/Gui/Resources/translations/StartPage_$lang_Code.qm
	echo "Finish. Now you may re-build FreeCAD to see updated translation for StartPage_$lang_Code_Upper_Case";; 
    "TechDraw.ts")
	echo "TechDraw.ts"
	lrelease  TechDraw.ts
	cp TechDraw.ts ~/$FreeCAD/src/Mod/TechDraw/Gui/Resources/translations/TechDraw_$lang_Code.ts
	cp TechDraw.qm ~/$FreeCAD/src/Mod/TechDraw/Gui/Resources/translations/TechDraw_$lang_Code.qm
	echo "Finish. Now you may re-build FreeCAD to see updated translation for TechDraw_$lang_Code_Upper_Case";; 
    "Test.ts")
	echo " Test.ts"
	lrelease  Test.ts
	cp Test.ts ~/$FreeCAD/src/Mod/Test/Gui/Resources/translations/Test_$lang_Code.ts
	cp Test.qm ~/$FreeCAD/src/Mod/Test/Gui/Resources/translations/Test_$lang_Code.qm
	echo "Finish. Now you may re-build FreeCAD to see updated translation for Test_$lang_Code_Upper_Case";; 
    "Tux.ts")
	echo "Tux.ts"
	lrelease  Tux.ts
	cp Tux.ts ~/$FreeCAD/src/Mod/Tux/Resources/translations/Tux_$lang_Code.ts
	cp Tux.qm ~/$FreeCAD/src/Mod/Tux/Resources/translations/Tux_$lang_Code.qm
	echo "Finish. Now you may re-build FreeCAD to see updated translation for Tux_$lang_Code_Upper_Case";; 
    "Web.ts")
	echo "Web.ts"
	lrelease  Web.ts
	cp Web.ts ~/$FreeCAD/src/Mod/Web/Gui/Resources/translations/Web_$lang_Code.ts
	cp Web.qm ~/$FreeCAD/src/Mod/Web/Gui/Resources/translations/Web_$lang_Code.qm
	echo "Finish. Now you may re-build FreeCAD to see updated translation for Web_$lang_Code_Upper_Case";; 
    *) echo "Run script with one of .ts file as argument!";;
esac
RealThunder's A3 Wiki translation, join the project https://crowdin.com/project/freecad-asm3-wiki
User avatar
kaktus
Veteran
Posts: 1174
Joined: Sun Aug 11, 2019 11:59 am
Location: opolskie
Contact:

Re: Small script for translator (for local work)

Post by kaktus »

Kuzma30

I'm not sure I understand your intentions.
Therefore, I will preempt the facts. :roll: FreeCAD does not need to be compiled every time for the changes in GUI translations to take effect. :idea:
Twórca polskiej wersji Wiki dla FreeCAD, współwórca polskiej wersji GUI.
"Cierpliwym być musisz, by wiedzę zgłębiać tajemną, gdyż ciemna strona mocy niszczącą i silną jest".
User avatar
Kuzma30
Posts: 163
Joined: Wed Oct 24, 2018 11:50 am
Location: Ukraine

Re: Small script for translator (for local work)

Post by Kuzma30 »

kaktus wrote: Sun Apr 17, 2022 1:01 pm Kuzma30

I'm not sure I understand your intentions.
Therefore, I will preempt the facts. :roll: FreeCAD does not need to be compiled every time for the changes in GUI translations to take effect. :idea:
When I place new .ts in FreeCAD source tree and re-run build, I always see for example Building of qrc_Sketcher.cpp.o and linking SketcherGui.o and PartDesignGui.o (I work with Skether.ts now) May be if I store all .ts files in predefined directory it will work without recompile. Not testing yet)
RealThunder's A3 Wiki translation, join the project https://crowdin.com/project/freecad-asm3-wiki
User avatar
kaktus
Veteran
Posts: 1174
Joined: Sun Aug 11, 2019 11:59 am
Location: opolskie
Contact:

Re: Small script for translator (for local work)

Post by kaktus »

kaktus wrote: Sat Apr 16, 2022 7:01 pm :mrgreen:

...

Today the FreeCAD-translations Testing section has been completed for translators testing in their environment.
There is a good dose of useful information there. ;)
It is worth to have a look there, I have completed the content ...
;)
Twórca polskiej wersji Wiki dla FreeCAD, współwórca polskiej wersji GUI.
"Cierpliwym być musisz, by wiedzę zgłębiać tajemną, gdyż ciemna strona mocy niszczącą i silną jest".
Post Reply