-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
2,796 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Environment variables | ||
.env | ||
|
||
# Python environment | ||
env/ | ||
|
||
# Compiled translation files | ||
*.mo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.