-
Notifications
You must be signed in to change notification settings - Fork 10
/
to_pomo
executable file
·51 lines (39 loc) · 1.07 KB
/
to_pomo
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env python
# -*- coding: utf8 -*-
from __future__ import unicode_literals
import os
import json
import polib
base_path = "public/locales"
try:
os.mkdir(base_path)
except:
pass
with open("public/rules.json", 'r') as f:
raw = json.load(f, encoding="utf-8")
for locale, rules in raw.items():
po = polib.POFile()
po.metadata = {
'Project-Id-Version': '1.0',
'Language': locale,
'Report-Msgid-Bugs-To': '[email protected]',
'MIME-Version': '1.0',
'Content-Type': 'text/plain; charset=utf-8',
'Content-Transfer-Encoding': '8bit',
}
for rule in rules:
base_id = "yslow.%s" % rule["id"]
entry = polib.POEntry(
msgid=base_id,
msgstr=rule["content"]
)
po.append(entry)
entry = polib.POEntry(
msgid="%s.title" % base_id,
msgstr=rule["title"]
)
po.append(entry)
po_path = "%s/%s.po" % (base_path, locale)
po.save(po_path)
mo_path = "%s/%s.mo" % (base_path, locale)
po.save_as_mofile(mo_path)