diff options
author | Alastrim <alasmirt@gmail.com> | 2023-05-21 23:42:23 -0300 |
---|---|---|
committer | Jesusaves <cpntb1@ymail.com> | 2023-05-21 23:42:23 -0300 |
commit | 18f290277e0efe329c08872dd7b08645c2eca8ec (patch) | |
tree | 018f47e6a6b2a0ff910a90ad39d0c15284c2637b /lang_client/fetch.py | |
parent | d03d4467445d6fc8bee385cf2e2499983dfced90 (diff) | |
download | tools-18f290277e0efe329c08872dd7b08645c2eca8ec.tar.gz tools-18f290277e0efe329c08872dd7b08645c2eca8ec.tar.bz2 tools-18f290277e0efe329c08872dd7b08645c2eca8ec.tar.xz tools-18f290277e0efe329c08872dd7b08645c2eca8ec.zip |
Update translations and scripts
Diffstat (limited to 'lang_client/fetch.py')
-rwxr-xr-x | lang_client/fetch.py | 76 |
1 files changed, 32 insertions, 44 deletions
diff --git a/lang_client/fetch.py b/lang_client/fetch.py index 7ddb59a..5c7460e 100755 --- a/lang_client/fetch.py +++ b/lang_client/fetch.py @@ -1,60 +1,48 @@ -#! /usr/bin/env python2.7 +#! /usr/bin/env python3 # -*- coding: utf8 -*- # # Copyright (C) 2018 TMW-2 -# Author: Jesusalva +# Author: Jesusalva, ntsneto -from transifex.api import TransifexAPI +from transifex.api import transifex_api +import requests -project='moubootaur-legends' +## Master translation control, see data/langs/langs.txt as master reference +TTL={"English": "en", "Portuguese (Brazil)": "pt_BR", "French": "fr", "German": "de", "Spanish": "es", "Russian": "ru", "Italian": "it"} -# Load credentials from login.txt and password.txt -login=open('../lang/login.txt', 'r') -for i in login: - username=i.replace('\n', '').replace('\r', '') +# Load API Token from apy_token_transifex.txt. You can generate one at https://www.transifex.com/user/settings/api/. -login.close() +with open("token.txt", "r") as f: + token = f.read() + token = str(token).replace('\n','') -passw=open('../lang/password.txt', 'r') -for i in passw: - password=i.replace('\n', '').replace('\r', '') +transifex_api.setup(auth=token) -passw.close() +organization_name = "arctic-games" +project_name = "moubootaur-legends" +resource_name = "clientdata" -t=TransifexAPI(username, password, 'https://www.transifex.com') +organization = transifex_api.Organization.get(slug=organization_name) -if (not t.ping): - print("ERROR: Ping failed, this may be due incorrect username/password in login.txt and password.txt. Ensure there is NO newline at the end of file. At lang/ folder.") - exit(1) +print(f"Getting project details from organization {organization_name}") +project = organization.fetch("projects").get(slug=project_name) -if (not t.project_exists(project)): - print("ERROR: Invalid project name") - exit(1) - -# Load languages -langs=[] -vcx=open("../../server-data/langs/langs.txt", "r") -for i in vcx: - if i != "en": - langs.append(i.replace('\n', '')) -vcx.close() +print(f"Getting resource {resource_name} from project {project_name}") +resource = project.fetch("resources").get(slug=resource_name) # Fetch all translations and record them at in/ -for i in langs: - # Disregarded languages - if i in ['en', 'vls']: - continue - - # People translated so we cannot override stuff - #if i in ['pt_BR', 'vls']: - # print("Overriding %s..." %(i)) - # t.new_translation(project, 'clientdata', i,'../../client-data/translations/'+str(i)+'.po') - print("Fetching %s..." %(i)) - t.get_translation(project, 'clientdata', i, '../../client-data/translations/'+str(i)+'.po') - - """ - print("Fetching %s dict..." %(i)) - t.get_translation(project, 'clientdata-dict', i, '../../client-data/translations/dict/'+str(i)+'.po') - """ +print(f"Getting languages from project {project_name}") +languages = project.fetch("languages") +for lang in languages: + url = transifex_api.ResourceTranslationsAsyncDownload.download(resource=resource, language=lang) + translated_content = requests.get(url).text + print(f"Fetching {lang.name}") + try: + code = TTL[lang.name] + except: + print(f"{lang.name} is unsupported, SKIPPED") + continue + with open(f"../../client-data/translations/{code}.po", "w", encoding="UTF-8") as f: + print(translated_content, file=f) |