Handle of new BLF_I18N_MSGID_MULTI_CTXT macro, which allows to define a same msgid in up to 16 different contexts at once.
This commit is contained in:
@@ -114,6 +114,9 @@ DOMAIN = "blender"
|
|||||||
# File type (ext) to parse.
|
# File type (ext) to parse.
|
||||||
PYGETTEXT_ALLOWED_EXTS = {".c", ".cpp", ".cxx", ".hpp", ".hxx", ".h"}
|
PYGETTEXT_ALLOWED_EXTS = {".c", ".cpp", ".cxx", ".hpp", ".hxx", ".h"}
|
||||||
|
|
||||||
|
# Max number of contexts into a BLF_I18N_MSGID_MULTI_CTXT macro...
|
||||||
|
PYGETTEXT_MAX_MULTI_CTXT = 16
|
||||||
|
|
||||||
# Where to search contexts definitions, relative to SOURCE_DIR (defined below).
|
# Where to search contexts definitions, relative to SOURCE_DIR (defined below).
|
||||||
PYGETTEXT_CONTEXTS_DEFSRC = os.path.join("source", "blender", "blenfont",
|
PYGETTEXT_CONTEXTS_DEFSRC = os.path.join("source", "blender", "blenfont",
|
||||||
"BLF_translation.h")
|
"BLF_translation.h")
|
||||||
@@ -149,7 +152,10 @@ _str_whole_re = (
|
|||||||
# End of loop.
|
# End of loop.
|
||||||
"))*"
|
"))*"
|
||||||
)
|
)
|
||||||
_ctxt_re = r"(?P<ctxt_raw>(?:" + _str_whole_re.format(_="_ctxt") + r")|(?:[A-Z_0-9]+))"
|
_ctxt_re_gen = lambda uid : r"(?P<ctxt_raw{uid}>(?:".format(uid=uid) + \
|
||||||
|
_str_whole_re.format(_="_ctxt{uid}".format(uid=uid)) + \
|
||||||
|
r")|(?:[A-Z_0-9]+))"
|
||||||
|
_ctxt_re = _ctxt_re_gen("")
|
||||||
_msg_re = r"(?P<msg_raw>" + _str_whole_re.format(_="_msg") + r")"
|
_msg_re = r"(?P<msg_raw>" + _str_whole_re.format(_="_msg") + r")"
|
||||||
PYGETTEXT_KEYWORDS = (() +
|
PYGETTEXT_KEYWORDS = (() +
|
||||||
tuple((r"{}\(\s*" + _msg_re + r"\s*\)").format(it)
|
tuple((r"{}\(\s*" + _msg_re + r"\s*\)").format(it)
|
||||||
@@ -165,7 +171,11 @@ PYGETTEXT_KEYWORDS = (() +
|
|||||||
for it in ("BMO_error_raise",)) +
|
for it in ("BMO_error_raise",)) +
|
||||||
|
|
||||||
tuple(("{}\\((?:[^\"',]+,)\\s*" + _msg_re + r"\s*(?:\)|,)").format(it)
|
tuple(("{}\\((?:[^\"',]+,)\\s*" + _msg_re + r"\s*(?:\)|,)").format(it)
|
||||||
for it in ("modifier_setError",))
|
for it in ("modifier_setError",)) +
|
||||||
|
|
||||||
|
tuple((r"{}\(\s*" + _msg_re + r"\s*,\s*(?:" + \
|
||||||
|
r"\s*,\s*)?(?:".join(_ctxt_re_gen(i) for i in range(PYGETTEXT_MAX_MULTI_CTXT)) + r")?\s*\)").format(it)
|
||||||
|
for it in ("BLF_I18N_MSGID_MULTI_CTXT",))
|
||||||
)
|
)
|
||||||
|
|
||||||
ESCAPE_RE = (
|
ESCAPE_RE = (
|
||||||
|
@@ -52,6 +52,7 @@ SRC_POTFILES = settings.FILE_NAME_SRC_POTFILES
|
|||||||
|
|
||||||
CONTEXT_DEFAULT = settings.CONTEXT_DEFAULT
|
CONTEXT_DEFAULT = settings.CONTEXT_DEFAULT
|
||||||
PYGETTEXT_ALLOWED_EXTS = settings.PYGETTEXT_ALLOWED_EXTS
|
PYGETTEXT_ALLOWED_EXTS = settings.PYGETTEXT_ALLOWED_EXTS
|
||||||
|
PYGETTEXT_MAX_MULTI_CTXT = settings.PYGETTEXT_MAX_MULTI_CTXT
|
||||||
|
|
||||||
SVN_EXECUTABLE = settings.SVN_EXECUTABLE
|
SVN_EXECUTABLE = settings.SVN_EXECUTABLE
|
||||||
|
|
||||||
@@ -79,6 +80,31 @@ clean_str = lambda s: "".join(m.group("clean") for m in _clean_str(s))
|
|||||||
|
|
||||||
|
|
||||||
def check_file(path, rel_path, messages):
|
def check_file(path, rel_path, messages):
|
||||||
|
def process_entry(ctxt, msg):
|
||||||
|
# Context.
|
||||||
|
if ctxt:
|
||||||
|
if ctxt in CONTEXTS:
|
||||||
|
ctxt = CONTEXTS[ctxt]
|
||||||
|
elif '"' in ctxt or "'" in ctxt:
|
||||||
|
ctxt = clean_str(ctxt)
|
||||||
|
else:
|
||||||
|
print("WARNING: raw context “{}” couldn’t be resolved!"
|
||||||
|
"".format(ctxt))
|
||||||
|
ctxt = CONTEXT_DEFAULT
|
||||||
|
else:
|
||||||
|
ctxt = CONTEXT_DEFAULT
|
||||||
|
# Message.
|
||||||
|
if msg:
|
||||||
|
if '"' in msg or "'" in msg:
|
||||||
|
msg = clean_str(msg)
|
||||||
|
else:
|
||||||
|
print("WARNING: raw message “{}” couldn’t be resolved!"
|
||||||
|
"".format(msg))
|
||||||
|
msg = ""
|
||||||
|
else:
|
||||||
|
msg = ""
|
||||||
|
return (ctxt, msg)
|
||||||
|
|
||||||
with open(path, encoding="utf-8") as f:
|
with open(path, encoding="utf-8") as f:
|
||||||
f = f.read()
|
f = f.read()
|
||||||
for srch in pygettexts:
|
for srch in pygettexts:
|
||||||
@@ -86,34 +112,23 @@ def check_file(path, rel_path, messages):
|
|||||||
line = pos = 0
|
line = pos = 0
|
||||||
while m:
|
while m:
|
||||||
d = m.groupdict()
|
d = m.groupdict()
|
||||||
# Context.
|
|
||||||
ctxt = d.get("ctxt_raw")
|
|
||||||
if ctxt:
|
|
||||||
if ctxt in CONTEXTS:
|
|
||||||
ctxt = CONTEXTS[ctxt]
|
|
||||||
elif '"' in ctxt or "'" in ctxt:
|
|
||||||
ctxt = clean_str(ctxt)
|
|
||||||
else:
|
|
||||||
print("WARNING: raw context “{}” couldn’t be resolved!"
|
|
||||||
"".format(ctxt))
|
|
||||||
ctxt = CONTEXT_DEFAULT
|
|
||||||
else:
|
|
||||||
ctxt = CONTEXT_DEFAULT
|
|
||||||
# Message.
|
|
||||||
msg = d.get("msg_raw")
|
|
||||||
if msg:
|
|
||||||
if '"' in msg or "'" in msg:
|
|
||||||
msg = clean_str(msg)
|
|
||||||
else:
|
|
||||||
print("WARNING: raw message “{}” couldn’t be resolved!"
|
|
||||||
"".format(msg))
|
|
||||||
msg = ""
|
|
||||||
else:
|
|
||||||
msg = ""
|
|
||||||
# Line.
|
# Line.
|
||||||
line += f[pos:m.start()].count('\n')
|
line += f[pos:m.start()].count('\n')
|
||||||
# And we are done for this item!
|
msg = d.get("msg_raw")
|
||||||
messages.setdefault((ctxt, msg), []).append(":".join((rel_path, str(line))))
|
# First, try the "multi-contexts" stuff!
|
||||||
|
ctxts = tuple(d.get("ctxt_raw{}".format(i)) for i in range(PYGETTEXT_MAX_MULTI_CTXT))
|
||||||
|
if ctxts[0]:
|
||||||
|
for ctxt in ctxts:
|
||||||
|
if not ctxt:
|
||||||
|
break
|
||||||
|
ctxt, _msg = process_entry(ctxt, msg)
|
||||||
|
# And we are done for this item!
|
||||||
|
messages.setdefault((ctxt, _msg), []).append(":".join((rel_path, str(line))))
|
||||||
|
else:
|
||||||
|
ctxt = d.get("ctxt_raw")
|
||||||
|
ctxt, msg = process_entry(ctxt, msg)
|
||||||
|
# And we are done for this item!
|
||||||
|
messages.setdefault((ctxt, msg), []).append(":".join((rel_path, str(line))))
|
||||||
pos = m.end()
|
pos = m.end()
|
||||||
line += f[m.start():pos].count('\n')
|
line += f[m.start():pos].count('\n')
|
||||||
m = srch(f, pos)
|
m = srch(f, pos)
|
||||||
@@ -138,12 +153,12 @@ def py_xgettext(messages):
|
|||||||
rel_path = os.path.relpath(path, SOURCE_DIR)
|
rel_path = os.path.relpath(path, SOURCE_DIR)
|
||||||
if rel_path in forbidden:
|
if rel_path in forbidden:
|
||||||
continue
|
continue
|
||||||
elif rel_path in forced:
|
elif rel_path not in forced:
|
||||||
forced.remove(rel_path)
|
forced.add(rel_path)
|
||||||
check_file(path, rel_path, messages)
|
for rel_path in sorted(forced):
|
||||||
for path in forced:
|
path = os.path.join(SOURCE_DIR, rel_path)
|
||||||
if os.path.exists(path):
|
if os.path.exists(path):
|
||||||
check_file(os.path.join(SOURCE_DIR, path), path, messages)
|
check_file(path, rel_path, messages)
|
||||||
|
|
||||||
|
|
||||||
# Spell checking!
|
# Spell checking!
|
||||||
|
Reference in New Issue
Block a user