Skip to content

Commit

Permalink
Add latest translation files
Browse files Browse the repository at this point in the history
  • Loading branch information
akprasad committed Sep 21, 2022
1 parent b31f688 commit 7989f55
Show file tree
Hide file tree
Showing 6 changed files with 2,796 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Environment variables
.env

# Python environment
env/

# Compiled translation files
*.mo
53 changes: 53 additions & 0 deletions fetch_latest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/usr/bin/env python

"""Fetch the latest translation files from Transifex.
NOTE: fetching a `message.po` file takes about 5 seconds per language.
"""

import os
from pathlib import Path

import dotenv
import requests
from transifex.api import transifex_api as api


dotenv.load_dotenv()
ALLOWED_LANGUAGES = ['sa', 'mr_IN', 'te_IN']
TRANSIFEX_API_TOKEN = os.environ['TRANSIFEX_API_TOKEN']

api.setup(auth=TRANSIFEX_API_TOKEN)


def download_messages_po(resource, language):
code: str = language.attributes['code']
if code not in ALLOWED_LANGUAGES:
return

path = Path(f'translations/{code}/LC_MESSAGES/messages.po')
if not path.parent.exists():
path.parent.mkdir(parents=True, exist_ok=True)

url = api.ResourceTranslationsAsyncDownload.download(resource=resource, language=language)
text = requests.get(url).text
path.write_text(text)

print(f'Wrote latest data to: {path}')


def main():
languages = api.Project.get(organization='o:ambuda', slug='ambuda').fetch('languages')
resources = api.Resource.filter(project='o:ambuda:p:ambuda')
assert len(resources) == 1
resource = resources[0]

for lang in languages:
code = lang.attributes['code']
if code not in ALLOWED_LANGUAGES:
continue

download_messages_po(resource, lang)


main()
21 changes: 21 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
asttokens==2.0.8
black==22.8.0
certifi==2022.9.14
charset-normalizer==2.1.1
click==8.1.3
future==0.18.2
idna==3.4
mypy-extensions==0.4.3
parsimonious==0.10.0
pathspec==0.10.1
platformdirs==2.5.2
pyseeyou==1.0.2
python-dotenv==0.21.0
pytz==2022.2.1
regex==2022.9.13
requests==2.28.1
six==1.16.0
tomli==2.0.1
toolz==0.12.0
transifex-python==3.0.2
urllib3==1.26.12

0 comments on commit 7989f55

Please sign in to comment.