Skip to content

Commit

Permalink
Update update.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Foxushka authored Sep 2, 2023
1 parent 708fbb9 commit 31def21
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions chameleonultragui/lib/l10n/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from urllib.request import Request, urlopen


def progressbar(it, prefix="", size=60, out=sys.stdout):
def progressbar(it, prefix='', size=60, out=sys.stdout):
count = len(it)

def show(j):
Expand All @@ -16,7 +16,7 @@ def show(j):
for i, item in enumerate(it):
yield item
show(i + 1)
print("\n", flush=True, file=out)
print('\n', flush=True, file=out)


def request(method, url, data=None):
Expand All @@ -28,17 +28,24 @@ def request(method, url, data=None):
'Content-Type': 'application/json'})).read().decode())


for language in progressbar(request('GET', 'https://crowdin.com/api/v2/projects/610545/files/9/languages/progress?limit=500')['data']):
LANGUAGES = request('GET', 'https://crowdin.com/api/v2/languages?limit=500')['data']

for language in progressbar(
request('GET', 'https://crowdin.com/api/v2/projects/610545/files/9/languages/progress?limit=500')['data']):
try:
progress = request('GET',
f'https://crowdin.com/api/v2/projects/610545/languages/{language["data"]["id"]}/progress')
f"https://crowdin.com/api/v2/projects/610545/languages/{language['data']['languageId']}/progress")
except urllib.error.HTTPError:
continue
if progress['data'][0]['data']['words']['translated']:
translation = request("POST", "https://crowdin.com/api/v2/projects/610545/translations/exports",
{"targetLanguageId": language["data"]["id"], "format": "arb-export",
"skipUntranslatedStrings": True, "fileIds": [9]})
translation = request('POST', 'https://crowdin.com/api/v2/projects/610545/translations/exports',
{'targetLanguageId': language['data']['languageId'], 'format': 'arb-export',
'skipUntranslatedStrings': True, 'fileIds': [9]})
export = urlopen(Request(translation['data']['url'], method='GET')).read()
translations = json.loads(export.decode())
translations['@@locale'] = language['data']['osxLocale']
json.dump(translations, open(f"app_{language['data']['osxLocale']}.arb", "w+"), indent=2)
locale = None
for lang in LANGUAGES:
if lang['data']['id'] == language['data']['languageId']:
locale = lang['data']['osxLocale']
translations['@@locale'] = locale
json.dump(translations, open(f'app_{locale}.arb', 'w+'), indent=2)

0 comments on commit 31def21

Please sign in to comment.