forked from zulip/zulip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtagmessages
executable file
·28 lines (24 loc) · 1.13 KB
/
tagmessages
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
#!/usr/bin/env python3
import configparser
import os
from hashlib import md5
import polib
THIS_DIR = os.path.dirname(os.path.realpath(__file__))
config = configparser.RawConfigParser()
config.read(os.path.join(THIS_DIR, '../.transifexrc'))
login = '{}:{}'.format(config.get('https://www.transifex.com', 'username'),
config.get('https://www.transifex.com', 'password'))
project_slug = 'zulip-test' # HACK hardcode
tools_dir = os.path.dirname(os.path.abspath(__file__))
root_dir = os.path.dirname(tools_dir)
# Choose any translation file for processing all strings.
po = polib.pofile(os.path.join(root_dir, 'locale', 'de', 'LC_MESSAGES', 'django.po'))
for entry in po:
tag = entry.comment
if tag:
keys = [entry.msgid, entry.msgctxt or '']
msg_hash = md5(':'.join(keys).encode('utf-8')).hexdigest()
curl_call = 'curl -i -L --user {} -X PUT -H "Content-Type: application/json" ' \
'--data \'{{"tags": ["{}"]}}\' https://www.transifex.com/api/2/project/{}/resource' \
'/djangopo/source/{}'.format(login, tag, project_slug, msg_hash)
os.system(curl_call)