mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-19 14:38:18 +00:00
Update scripts/convert_l10n.py to use regexes
This commit is contained in:
parent
b5f7549192
commit
d3f416f830
|
@ -1,6 +1,7 @@
|
||||||
import json
|
import json
|
||||||
import polib
|
import polib
|
||||||
import os
|
import os
|
||||||
|
import re
|
||||||
import time
|
import time
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
@ -18,14 +19,18 @@ JSON_KEY_OLDTRANSL="old translations"
|
||||||
JSON_KEY_OR="or"
|
JSON_KEY_OR="or"
|
||||||
JSON_KEY_TR="tr"
|
JSON_KEY_TR="tr"
|
||||||
|
|
||||||
|
SOURCE_LOCALIZE_RE=re.compile(br'Localize\("(?P<str>([^"\\]|\\.)*)"(, "(?P<ctxt>([^"\\]|\\.)*)")?\)')
|
||||||
|
|
||||||
def parse_source():
|
def parse_source():
|
||||||
l10n = defaultdict(lambda: [])
|
l10n = defaultdict(lambda: [])
|
||||||
|
|
||||||
def process_line(line, filename, lineno):
|
def process_line(line, filename, lineno):
|
||||||
if b"Localize(\"" in line:
|
for match in SOURCE_LOCALIZE_RE.finditer(line):
|
||||||
fields = line.split(b"Localize(\"", 1)[1].split(b"\"", 1)
|
str_ = match.group('str').decode()
|
||||||
l10n[fields[0].decode()].append((filename, lineno))
|
ctxt = match.group('ctxt')
|
||||||
process_line(fields[1], filename, lineno)
|
if ctxt is not None:
|
||||||
|
ctxt = ctxt.decode()
|
||||||
|
l10n[(str_, ctxt)].append((filename, lineno))
|
||||||
|
|
||||||
for root, dirs, files in os.walk("src"):
|
for root, dirs, files in os.walk("src"):
|
||||||
for name in files:
|
for name in files:
|
||||||
|
@ -104,8 +109,8 @@ if __name__ == '__main__':
|
||||||
'Content-Type': 'text/plain; charset=utf-8',
|
'Content-Type': 'text/plain; charset=utf-8',
|
||||||
'Content-Transfer-Encoding': '8bit',
|
'Content-Transfer-Encoding': '8bit',
|
||||||
}
|
}
|
||||||
for msg, occurrences in l10n_src.items():
|
for (msg, ctxt), occurrences in l10n_src.items():
|
||||||
po.append(polib.POEntry(msgid=msg, msgstr="", occurrences=occurrences))
|
po.append(polib.POEntry(msgid=msg, msgstr="", occurrences=occurrences, msgctxt=ctxt))
|
||||||
po.save('data/languages/base.pot')
|
po.save('data/languages/base.pot')
|
||||||
|
|
||||||
for filename in os.listdir("data/languages"):
|
for filename in os.listdir("data/languages"):
|
||||||
|
|
Loading…
Reference in a new issue