aboutsummaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2021-09-06 11:59:42 -0700
committerAshutosh Bishnoi <mail2bishnoi@gmail.com>2022-02-15 11:28:09 +0530
commit682bc9db991ef5d550b6b0b780371f19359511ad (patch)
tree261e25a5edc102fa31c19af1fe365ebb89cd8d34 /tools
parent158f8ba27f354b53f4d25613d1ff1828cbad0bea (diff)
downloadtrackermap-web-682bc9db991ef5d550b6b0b780371f19359511ad.tar.gz
trackermap-web-682bc9db991ef5d550b6b0b780371f19359511ad.tar.bz2
trackermap-web-682bc9db991ef5d550b6b0b780371f19359511ad.zip
# This is a combination of 30 commits.
# This is the 1st commit message: Close socket on logout (fix #896) # This is the commit message #2: Fix lint # This is the commit message #3: Add calendar menu # This is the commit message #4: Add calendar file upload # This is the commit message #5: Disable icon tinting in Firefox # This is the commit message #6: Move ignition icon # This is the commit message #7: Specify icon sizes # This is the commit message #8: Fix lint issues # This is the commit message #9: Add accuracy button # This is the commit message #10: Merge shock and vibration alarms # This is the commit message #11: Add events alarm column # This is the commit message #12: Enable LocationIQ by default # This is the commit message #13: Update LocationIQ keys # This is the commit message #14: Fix selector style # This is the commit message #15: Support server change # This is the commit message #16: Update localization script # This is the commit message #17: Update localization # This is the commit message #18: Command to install dependency # This is the commit message #19: Update JavaScript libraries # This is the commit message #20: Fix modern app issues # This is the commit message #21: Fix image URL # This is the commit message #22: Fix user list (fix #898) # This is the commit message #23: Fix formatting issue # This is the commit message #24: Add option to disable reports # This is the commit message #25: Fix add button position # This is the commit message #26: Select device based on uniqueId # This is the commit message #27: Update devices list search # This is the commit message #28: Fix lint problems # This is the commit message #29: Changed devices list search # This is the commit message #30: Changed device list search
Diffstat (limited to 'tools')
-rwxr-xr-xtools/translate.py41
1 files changed, 19 insertions, 22 deletions
diff --git a/tools/translate.py b/tools/translate.py
index e8324a61..43e90849 100755
--- a/tools/translate.py
+++ b/tools/translate.py
@@ -1,35 +1,32 @@
-#!/usr/bin/python
+#!/usr/local/bin/python3
+
+# pip3 install --upgrade transifex-python
import os
import optparse
-import urllib2
-import json
-import base64
+import requests
+from transifex.api import transifex_api
parser = optparse.OptionParser()
-parser.add_option("-u", "--user", dest="username", help="transifex user login")
-parser.add_option("-p", "--password", dest="password", help="transifex user password")
+parser.add_option("-t", "--token", dest="token", help="transifex token")
(options, args) = parser.parse_args()
-if not options.username or not options.password:
- parser.error('User name and password are required')
+if not options.token:
+ parser.error('Token is required')
os.chdir(os.path.dirname(os.path.abspath(__file__)))
-path = "../web/l10n/"
-
-def request(url):
- req = urllib2.Request(url)
- auth = base64.encodestring("%s:%s" % (options.username, options.password)).replace("\n", "")
- req.add_header("Authorization", "Basic %s" % auth)
- return urllib2.urlopen(req)
+transifex_api.setup(auth=options.token)
-resource = json.load(request("https://www.transifex.com/api/2/project/traccar/resource/web/?details"))
+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 resource["available_languages"]:
- code = language["code"]
- data = request("https://www.transifex.com/api/2/project/traccar/resource/web/translation/" + code + "?file")
- file = open(path + code + ".json", "wb")
- file.write(data.read())
- file.close()
+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)