contrib/push_locale: minor clean-up
This commit is contained in:
@@ -79,18 +79,15 @@ subprocess.check_output(cmd, shell=True)
|
|||||||
os.chdir(os.path.join(project_root, "electrum"))
|
os.chdir(os.path.join(project_root, "electrum"))
|
||||||
|
|
||||||
crowdin_api_key = None
|
crowdin_api_key = None
|
||||||
|
|
||||||
filename = os.path.expanduser('~/.crowdin_api_key')
|
filename = os.path.expanduser('~/.crowdin_api_key')
|
||||||
if os.path.exists(filename):
|
if os.path.exists(filename):
|
||||||
with open(filename) as f:
|
with open(filename) as f:
|
||||||
crowdin_api_key = f.read().strip()
|
crowdin_api_key = f.read().strip()
|
||||||
|
|
||||||
if "crowdin_api_key" in os.environ:
|
if "crowdin_api_key" in os.environ:
|
||||||
crowdin_api_key = os.environ["crowdin_api_key"]
|
crowdin_api_key = os.environ["crowdin_api_key"]
|
||||||
|
|
||||||
if not crowdin_api_key:
|
if not crowdin_api_key:
|
||||||
print('Missing crowdin_api_key. Cannot push.')
|
print('Missing crowdin_api_key. Cannot push.')
|
||||||
sys.exit(0)
|
sys.exit(1)
|
||||||
print('Found crowdin_api_key. Will push updated source-strings to crowdin.')
|
print('Found crowdin_api_key. Will push updated source-strings to crowdin.')
|
||||||
|
|
||||||
crowdin_project_id = 20482 # for "Electrum" project on crowdin
|
crowdin_project_id = 20482 # for "Electrum" project on crowdin
|
||||||
@@ -100,24 +97,30 @@ crowdin_file_id = 68 # for "/electrum-client/messages.pot"
|
|||||||
global_headers = {"Authorization": "Bearer {}".format(crowdin_api_key)}
|
global_headers = {"Authorization": "Bearer {}".format(crowdin_api_key)}
|
||||||
|
|
||||||
# client.storages.add_storage(f)
|
# client.storages.add_storage(f)
|
||||||
|
# https://support.crowdin.com/developer/api/v2/?q=api#tag/Storage/operation/api.storages.post
|
||||||
print(f"Uploading to temp storage...")
|
print(f"Uploading to temp storage...")
|
||||||
url = f'https://api.crowdin.com/api/v2/storages'
|
url = f'https://api.crowdin.com/api/v2/storages'
|
||||||
with open(locale_file_name, 'rb') as f:
|
with open(locale_file_name, 'rb') as f:
|
||||||
headers = {**global_headers, **{"Crowdin-API-FileName": crowdin_file_name}}
|
headers = {**global_headers, **{"Crowdin-API-FileName": crowdin_file_name}}
|
||||||
response = requests.request("POST", url, data=f, headers=headers)
|
response = requests.request("POST", url, data=f, headers=headers)
|
||||||
|
response.raise_for_status()
|
||||||
print("", "storages.add_storage:", "-" * 20, response.text, "-" * 20, sep="\n")
|
print("", "storages.add_storage:", "-" * 20, response.text, "-" * 20, sep="\n")
|
||||||
storage_id = response.json()["data"]["id"]
|
storage_id = response.json()["data"]["id"]
|
||||||
|
|
||||||
# client.source_files.update_file(projectId=crowdin_project_id, storageId=storage_id, fileId=crowdin_file_id)
|
# client.source_files.update_file(projectId=crowdin_project_id, storageId=storage_id, fileId=crowdin_file_id)
|
||||||
|
# https://support.crowdin.com/developer/api/v2/?q=api#tag/Source-Files/operation/api.projects.files.put
|
||||||
print(f"Copying from temp storage and updating file in perm storage...")
|
print(f"Copying from temp storage and updating file in perm storage...")
|
||||||
url = f'https://api.crowdin.com/api/v2/projects/{crowdin_project_id}/files/{crowdin_file_id}'
|
url = f'https://api.crowdin.com/api/v2/projects/{crowdin_project_id}/files/{crowdin_file_id}'
|
||||||
headers = {**global_headers, **{"content-type": "application/json"}}
|
headers = {**global_headers, **{"content-type": "application/json"}}
|
||||||
response = requests.request("PUT", url, json={"storageId": storage_id}, headers=headers)
|
response = requests.request("PUT", url, json={"storageId": storage_id}, headers=headers)
|
||||||
|
response.raise_for_status()
|
||||||
print("", "source_files.update_file:", "-" * 20, response.text, "-" * 20, sep="\n")
|
print("", "source_files.update_file:", "-" * 20, response.text, "-" * 20, sep="\n")
|
||||||
|
|
||||||
# client.translations.build_crowdin_project_translation(projectId=crowdin_project_id)
|
# client.translations.build_crowdin_project_translation(projectId=crowdin_project_id)
|
||||||
|
# https://support.crowdin.com/developer/api/v2/?q=api#tag/Translations/operation/api.projects.translations.builds.post
|
||||||
print(f"Rebuilding translations...")
|
print(f"Rebuilding translations...")
|
||||||
url = f'https://api.crowdin.com/api/v2/projects/{crowdin_project_id}/translations/builds'
|
url = f'https://api.crowdin.com/api/v2/projects/{crowdin_project_id}/translations/builds'
|
||||||
headers = {**global_headers, **{"content-type": "application/json"}}
|
headers = {**global_headers, **{"content-type": "application/json"}}
|
||||||
response = requests.request("POST", url, headers=headers)
|
response = requests.request("POST", url, headers=headers)
|
||||||
|
response.raise_for_status()
|
||||||
print("", "translations.build_crowdin_project_translation:", "-" * 20, response.text, "-" * 20, sep="\n")
|
print("", "translations.build_crowdin_project_translation:", "-" * 20, response.text, "-" * 20, sep="\n")
|
||||||
|
|||||||
Reference in New Issue
Block a user