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:
and set to languge what you need. Italian for example.
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.