How regularly is the archive with translations in crowdin updates?

Have some feature requests, feedback, cool stuff to share, or want to know where FreeCAD is going? This is the place.
Forum rules
Be nice to others! Read the FreeCAD code of conduct!
Post Reply
User avatar
Evgeniy
Posts: 477
Joined: Thu Jul 15, 2021 6:10 pm

Re: How regularly is the archive with translations in crowdin updates?

Post by Evgeniy »

That Works. But this is blotting is real dissapointed me...
chennes wrote: Wed Sep 08, 2021 10:34 pm then created the folder "languages" in the
1) Download *.ts files from Crowdin (or full archive at once and extract it)
2) Rename all *.ts files to *_language.ts
for example for Russians translation files will be reanamed as:

FreeCAD.ts to FreeCAD_ru.ts
Arch.ts to Arch_ru.ts
Part.ts to Part_ru.ts
etc each file...

3) Convert *.ts to *.qm you may use QT Lingust (item menu Release as...)
4) Create "translations" folder into $USER/AppData/Roaming/FreeCAD/
5) Copy *.qm files to $USER/AppData/Roaming/FreeCAD/translations folder
6) Run freeCAD
7) This will work even if you copy only one file too.
For example if you copy only one FreeCAD_ru.qm to $USER/AppData/Roaming/FreeCAD/translations that will work.

Result is:
Works.png
Works.png (30.43 KiB) Viewed 1981 times
User avatar
Kunda1
Veteran
Posts: 13434
Joined: Thu Jan 05, 2017 9:03 pm

Re: How regularly is the archive with translations in crowdin updates?

Post by Kunda1 »

Evgeniy wrote: Thu Sep 09, 2021 3:39 pm That Works. But this is blotting is real dissapointed me...
Huh? You mean all the steps that need to happen?
Perhaps then we can create a cross-platform script for translators that auto-magically does this?
chennes wrote: Thu Sep 09, 2021 3:22 pm I think so, more or less. Here's a different way of summarizing, maybe it will be clearer than my last post :D --
Ahh...yes.. that's great! Should we open a ticket for this then?
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
Evgeniy
Posts: 477
Joined: Thu Jul 15, 2021 6:10 pm

Re: How regularly is the archive with translations in crowdin updates?

Post by Evgeniy »

Kunda1 wrote: Thu Sep 09, 2021 4:03 pm
Evgeniy wrote: Thu Sep 09, 2021 3:39 pm That Works. But this is blotting is real dissapointed me...
Huh? You mean all the steps that need to happen?
Perhaps then we can create a cross-platform script for translators that auto-magically does this?
I saw a similar script in the wiki and even tried to redo it for Windows, but I just didn't understand how it all works...


....

I will supplement. If I take FreeCAD_ru.qm and rename it to FreeCAD_bg.qm Bulgarian does not appear in the menu.
Last edited by Evgeniy on Thu Sep 09, 2021 4:08 pm, edited 1 time in total.
User avatar
Kunda1
Veteran
Posts: 13434
Joined: Thu Jan 05, 2017 9:03 pm

Re: How regularly is the archive with translations in crowdin updates?

Post by Kunda1 »

Evgeniy wrote: Thu Sep 09, 2021 4:06 pm I saw a similar script in the wiki and even tried to redo it for Windows, but I just didn't understand how it all works...
reference?
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
Evgeniy
Posts: 477
Joined: Thu Jul 15, 2021 6:10 pm

Re: How regularly is the archive with translations in crowdin updates?

Post by Evgeniy »

For other langages not presented in FreeCAD one only worked way is rename FreeCAD_af and select Afrikaans for example.
User avatar
Evgeniy
Posts: 477
Joined: Thu Jul 15, 2021 6:10 pm

Re: How regularly is the archive with translations in crowdin updates?

Post by Evgeniy »

Kunda1 wrote: Thu Sep 09, 2021 4:07 pm
Evgeniy wrote: Thu Sep 09, 2021 4:06 pm I saw a similar script in the wiki and even tried to redo it for Windows, but I just didn't understand how it all works...
reference?
I'll try to find it tomorrow
User avatar
chennes
Veteran
Posts: 3876
Joined: Fri Dec 23, 2016 3:38 pm
Location: Norman, OK, USA
Contact:

Re: How regularly is the archive with translations in crowdin updates?

Post by chennes »

Evgeniy wrote: Thu Sep 09, 2021 4:06 pm If I take FreeCAD_ru.qm and rename it to FreeCAD_bg.qm Bulgarian does not appear in the menu.
Right, that's the first feature I proposed in my previous post. It is a very easy bit of code to write, I'll try to put something together this afternoon.
Chris Hennes
Pioneer Library System
GitHub profile, LinkedIn profile, chrishennes.com
User avatar
Evgeniy
Posts: 477
Joined: Thu Jul 15, 2021 6:10 pm

Re: How regularly is the archive with translations in crowdin updates?

Post by Evgeniy »

Kunda1 wrote: Thu Sep 09, 2021 4:07 pm
Evgeniy wrote: Thu Sep 09, 2021 4:06 pm I saw a similar script in the wiki and even tried to redo it for Windows, but I just didn't understand how it all works...
reference?
The script is writed by Yorik and named as updatefromcrowdin.py
https://wiki.freecadweb.org/Crowdin_Scripts

but it is not allowed now.
https://github.com/FreeCAD/FreeCAD/blob ... crowdin.py

I think the script written by Yorik was used for the source code, i.e. it had a slightly different purpose.

Now i wrote a simpler and shorter script from scratch.

If you need update only one language uncomment this two strings:

Code: Select all

      #if fol!="ru":
      #   continue
and set to languge what you need. Italian for example.

Code: Select all

      if fol!="it":
         continue
The script works quite slowly as it requires many calls lrelease.exe
But it is completely automated. And compact.

Code: Select all

#! python
# -*- coding: utf-8 -*-
# <nowiki>(c) 2021 <Evgeniy> LGPL

import sys, os, zipfile, re
import urllib.request

crowdinpath = "https://crowdin.com/backend/download/project/freecad.zip"
            
# 1. Get path to $USER/AppData/Roaming/FreeCAD/ folder
path = App.getUserAppDataDir()
trans_path = os.path.join(path,"translations")
zip_path = os.path.join(path,"FreeCAD_zip")
# Create translation and FreeCAD_zip folder if it not exists
os.makedirs(trans_path, exist_ok = True)
os.makedirs(zip_path, exist_ok = True)

# 2. Check lrealase.exe utility in folder
lrel_path = os.path.join(path,"lrelase.exe")
if not os.path.exists(trans_path.replace("translations","lrelease.exe")):
   print(lrel_path+" is not found... process stopped")
   print("please copy lrelease.exe utilty to folder: "+trans_path.replace("translations","")+" and try again!")
   sys.exit(-1)

# 3. Download zip archive from crowdin
os.chdir(zip_path)
print("Try to download Crowdin archive from: " +crowdinpath)
urllib.request.urlretrieve(crowdinpath, 'freecad.zip')
if not os.path.exists("freecad.zip"):
	print("download from crowdin failed!")
	sys.exit(-1)
   
# 4. Unzip archive   
zfile=zipfile.ZipFile("freecad.zip")
print("extracting freecad.zip...")
zfile.extractall()

# 5. Translate all files with lrelease
os.chdir(path)
# Walk into FreeCAD unzipped folder and lrelease all files
for root,dirs,files in os.walk(zip_path):
   for fol in dirs:
      print("Scan folder: "+fol)
      #if fol!="ru":
      #   continue
      locale = fol
      for dirpath, subdirs, files in os.walk(zip_path+"/"+locale):
         for file in files:
            if file.endswith(".ts"):
               file_path = os.path.join(dirpath, file)
               print(file_path)
               os.system("lrelease "+file_path)
               qm_file_path=file_path.replace(".ts",".qm")
               if not os.path.exists(qm_file_path):
                  print("ERROR: impossible to create " + qm_file_path + " file, aborting")
                  sys.exit(-1)
               else:
                  qm_new_path=file_path.replace(".ts","_"+locale+".qm").replace("FreeCAD_zip/"+locale,"translations")
                  if os.path.exists(qm_new_path):
                     os.remove(qm_new_path)
                  os.rename(qm_file_path,qm_new_path)
I would like this script to be added to the Test Workbench. As instrumet for localization help.
User avatar
Evgeniy
Posts: 477
Joined: Thu Jul 15, 2021 6:10 pm

Re: How regularly is the archive with translations in crowdin updates?

Post by Evgeniy »

Much faster and better variant with using subprocess:

Code: Select all

#! python
# -*- coding: utf-8 -*-
# <nowiki>(c) 2021 <Evgeniy> LGPL

import sys, os, zipfile, re
import urllib.request
import subprocess

crowdinpath = "https://crowdin.com/backend/download/project/freecad.zip"
            
# 1. Get path to $USER/AppData/Roaming/FreeCAD/ folder
path = App.getUserAppDataDir()
trans_path = os.path.join(path,"translations")
zip_path = os.path.join(path,"FreeCAD_zip")
# Create translation and FreeCAD_zip folder if it not exists
os.makedirs(trans_path, exist_ok = True)
os.makedirs(zip_path, exist_ok = True)

# 2. Check lrealase.exe utility in folder
lrel_path = os.path.join(path,"lrelase.exe")
if not os.path.exists(trans_path.replace("translations","lrelease.exe")):
   print(lrel_path+" is not found... process stopped")
   print("please copy lrelease.exe utilty to folder: "+trans_path.replace("translations","")+" and try again!")
   sys.exit(-1)

# 3. Download zip archive from crowdin
os.chdir(zip_path)
print("Try to download Crowdin archive from: " +crowdinpath)
for i in range(0,10):
   FreeCADGui.updateGui()
urllib.request.urlretrieve(crowdinpath, 'freecad.zip')
if not os.path.exists("freecad.zip"):
	print("download from crowdin failed!")
	sys.exit(-1)
   
# 4. Unzip archive   
zfile=zipfile.ZipFile("freecad.zip")
print("Arhive is downloaded. Extracting it...")
for i in range(0,10):
   FreeCADGui.updateGui()
zfile.extractall()

# 5. Translate all files with lrelease
os.chdir(path)
# Walk into FreeCAD unzipped folder and lrelease all files
for root,dirs,files in os.walk(zip_path):
   for fol in dirs:
      print("Scan folder: "+fol)
      #if fol!="ru":
      #   continue
      locale = fol
      for dirpath, subdirs, files in os.walk(zip_path+"/"+locale):
         for file in files:
            if file.endswith(".ts"):
               file_path = os.path.join(dirpath, file)
               print(file_path)
               #os.system("lrelease "+file_path)
               FreeCADGui.updateGui()
               subprocess.call("lrelease "+file_path, shell=True, cwd=path)
               qm_file_path=file_path.replace(".ts",".qm")
               if not os.path.exists(qm_file_path):
                  print("ERROR: impossible to create " + qm_file_path + " file, aborting")
                  sys.exit(-1)
               else:
                  # Rename and move file
                  qm_new_path=file_path.replace(".ts","_"+locale+".qm").replace("FreeCAD_zip/"+locale,"translations")
                  if os.path.exists(qm_new_path):
                     os.remove(qm_new_path)
                  os.rename(qm_file_path,qm_new_path)
User avatar
chennes
Veteran
Posts: 3876
Joined: Fri Dec 23, 2016 3:38 pm
Location: Norman, OK, USA
Contact:

Re: How regularly is the archive with translations in crowdin updates?

Post by chennes »

I have some other ideas that I think might make testing new translations easier, but since I don't myself do any translating I don't have a good sense if these would actually help anyone:
  1. Add a hidden preference that controls whether translations in an external translations directory take precedence over internal
  2. Add a hidden preference that allows the addition of locale codes that aren't already built into FreeCAD
  3. Add a hidden preference that allows searching other paths for translations
Chris Hennes
Pioneer Library System
GitHub profile, LinkedIn profile, chrishennes.com
Post Reply