aboutsummaryrefslogtreecommitdiff
path: root/tools/translate.py
blob: 4c215fde2933bf7f5b7bc6e503dfa91376457fae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/local/bin/python3

# Requires transifex-python module

import os
import optparse
import requests
from transifex.api import transifex_api

parser = optparse.OptionParser()
parser.add_option("-t", "--token", dest="token", help="transifex token")

(options, args) = parser.parse_args()

if not options.token:
    parser.error('Token is required')

os.chdir(os.path.dirname(os.path.abspath(__file__)))

transifex_api.setup(auth=options.token)

organization = transifex_api.Organization.get(slug='traccar')
project = organization.fetch('projects').get(slug='traccar')
resource = project.fetch('resources').get(slug='web')
languages = project.fetch('languages')

for language in languages:
    print(language.code)
    url = transifex_api.ResourceTranslationsAsyncDownload.download(resource=resource, language=language)
    result = requests.get(url)
    with open('../web/l10n/' + language.code + '.json', "w") as file:
        file.write(result.text)