Tools: cosmetic tweaks to updatecrowdin script
This commit is contained in:
@@ -29,7 +29,7 @@ For it to work, you need a ~/.crowdin-freecad-token file in your user's folder,
|
||||
the API access token that gives access to the crowdin FreeCAD project.
|
||||
The API token can also be specified in the CROWDIN_TOKEN environment variable.
|
||||
|
||||
The CROWDIN_PROJECT_ID environment variable must be set.
|
||||
The CROWDIN_PROJECT_ID environment variable can be used to use this script in other projects.
|
||||
|
||||
Usage:
|
||||
|
||||
@@ -41,6 +41,7 @@ Available commands:
|
||||
update: updates crowdin the current version of .ts files found in the source code
|
||||
build: builds a new downloadable package on crowdin with all translated strings
|
||||
download [build_id]: downloads build specified by 'build_id' or latest if build_id is left blank
|
||||
apply: applies downloaded translations to source code (runs updatefromcrowdin.py)
|
||||
|
||||
Example:
|
||||
|
||||
@@ -137,14 +138,14 @@ class CrowdinUpdater:
|
||||
print(f'{filename} uploaded')
|
||||
|
||||
def status(self):
|
||||
response = self._make_project_api_req('/languages/progress')
|
||||
response = self._make_project_api_req('/languages/progress?limit=100')
|
||||
return [item['data'] for item in response]
|
||||
|
||||
def download(self, build_id):
|
||||
filename = f'{self.project_identifier}.zip'
|
||||
response = self._make_project_api_req(f'/translations/builds/{build_id}/download')
|
||||
urlretrieve(response['url'], filename)
|
||||
print('download complete')
|
||||
print('download of '+filename+' complete')
|
||||
|
||||
def build(self):
|
||||
self._make_project_api_req('/translations/builds', data={}, method='POST')
|
||||
@@ -192,17 +193,33 @@ if __name__ == "__main__":
|
||||
|
||||
project_identifier = os.environ.get('CROWDIN_PROJECT_ID')
|
||||
if not project_identifier:
|
||||
print('CROWDIN_PROJECT_ID env var must be set')
|
||||
sys.exit()
|
||||
project_identifier = "freecad"
|
||||
#print('CROWDIN_PROJECT_ID env var must be set')
|
||||
#sys.exit()
|
||||
|
||||
updater = CrowdinUpdater(token, project_identifier)
|
||||
|
||||
if command == "status":
|
||||
status = updater.status()
|
||||
status = sorted(status,key=lambda item: item['translationProgress'],reverse=True)
|
||||
print(len([item for item in status if item['translationProgress'] > 50])," languages with status > 50%:")
|
||||
print(" ")
|
||||
sep = False
|
||||
prefix = ""
|
||||
suffix = ""
|
||||
if os.name == "posix":
|
||||
prefix = "\033[;32m"
|
||||
suffix = "t\033[0m"
|
||||
for item in status:
|
||||
print(f"language: {item['languageId']}")
|
||||
print(f" translation progress: {item['translationProgress']}%")
|
||||
print(f" approval progress: {item['approvalProgress']}%")
|
||||
if item['translationProgress'] > 0:
|
||||
if (item['translationProgress'] < 50) and (not sep):
|
||||
print(" ")
|
||||
print("Other languages:")
|
||||
print(" ")
|
||||
sep = True
|
||||
print(prefix+f"language: {item['languageId']}"+suffix)
|
||||
print(f" translation progress: {item['translationProgress']}%")
|
||||
print(f" approval progress: {item['approvalProgress']}%")
|
||||
|
||||
elif command == "build-status":
|
||||
for item in updater.build_status():
|
||||
@@ -239,5 +256,10 @@ if __name__ == "__main__":
|
||||
ts_files = [TsFile(LEGACY_NAMING_MAP[a] if a in LEGACY_NAMING_MAP else a, b) for (a, b) in names_and_path]
|
||||
|
||||
updater.update(ts_files)
|
||||
|
||||
elif command == "apply":
|
||||
import updatefromcrowdin
|
||||
updatefromcrowdin.run()
|
||||
|
||||
else:
|
||||
print(__doc__)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/python
|
||||
#!/usr/bin/python3
|
||||
|
||||
#***************************************************************************
|
||||
#* *
|
||||
@@ -64,7 +64,8 @@ You can also run the script without any language code, in which case all the
|
||||
languages contained in the archive or directory will be added.
|
||||
'''
|
||||
|
||||
import sys, os, shutil, tempfile, zipfile, getopt, StringIO, re
|
||||
import sys, os, shutil, tempfile, zipfile, getopt, re
|
||||
import io as StringIO
|
||||
|
||||
crowdinpath = "http://crowdin.net/download/project/freecad.zip"
|
||||
|
||||
@@ -110,7 +111,7 @@ def updateqrc(qrcpath,lncode):
|
||||
if not os.path.exists(qrcpath):
|
||||
print("ERROR: Resource file " + qrcpath + " doesn't exist")
|
||||
sys.exit()
|
||||
f = open(qrcpath,"ro")
|
||||
f = open(qrcpath,"r")
|
||||
resources = []
|
||||
for l in f.readlines():
|
||||
resources.append(l)
|
||||
@@ -192,13 +193,13 @@ def doLanguage(lncode,fmodule=""):
|
||||
qrcpath = os.path.abspath(target[2])
|
||||
doFile(basefilepath,targetpath,lncode,qrcpath)
|
||||
print(lncode + " done!")
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
def run(args=[]):
|
||||
|
||||
global tempfolder
|
||||
inputdir = ""
|
||||
inputzip = ""
|
||||
fmodule = ""
|
||||
args = sys.argv[1:]
|
||||
if len(args) < 1:
|
||||
inputzip = os.path.join(os.path.abspath(os.curdir),"freecad.zip")
|
||||
if os.path.exists(inputzip):
|
||||
@@ -208,7 +209,7 @@ if __name__ == "__main__":
|
||||
sys.exit()
|
||||
else:
|
||||
try:
|
||||
opts, args = getopt.getopt(sys.argv[1:], "hd:z:m:", ["help", "directory=","zipfile=", "module="])
|
||||
opts, args = getopt.getopt(args, "hd:z:m:", ["help", "directory=","zipfile=", "module="])
|
||||
except getopt.GetoptError:
|
||||
print(__doc__)
|
||||
sys.exit()
|
||||
@@ -264,3 +265,8 @@ if __name__ == "__main__":
|
||||
print("ERROR: language path for " + ln + " not found!")
|
||||
else:
|
||||
doLanguage(ln,fmodule)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
run(sys.argv[1:])
|
||||
|
||||
Reference in New Issue
Block a user