diff options
author | Bastien Montagne <montagne29@wanadoo.fr> | 2012-11-23 19:35:16 +0400 |
---|---|---|
committer | Bastien Montagne <montagne29@wanadoo.fr> | 2012-11-23 19:35:16 +0400 |
commit | bb7fdc7935b8e909dfa10ec1dde654c6ce2f18a1 (patch) | |
tree | 0f8fb9cd8dc8b857733201fd32b3b80e29b69a7a /release | |
parent | 00b1d50532f4f1be1fcb310cefbbe8b285fd17ee (diff) |
Handle of new BLF_I18N_MSGID_MULTI_CTXT macro, which allows to define a same msgid in up to 16 different contexts at once.
Diffstat (limited to 'release')
-rw-r--r-- | release/scripts/modules/bl_i18n_utils/settings.py | 14 | ||||
-rwxr-xr-x | release/scripts/modules/bl_i18n_utils/update_pot.py | 77 |
2 files changed, 58 insertions, 33 deletions
diff --git a/release/scripts/modules/bl_i18n_utils/settings.py b/release/scripts/modules/bl_i18n_utils/settings.py index f61d14eda20..c7414e84046 100644 --- a/release/scripts/modules/bl_i18n_utils/settings.py +++ b/release/scripts/modules/bl_i18n_utils/settings.py @@ -114,6 +114,9 @@ DOMAIN = "blender" # File type (ext) to parse. 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). PYGETTEXT_CONTEXTS_DEFSRC = os.path.join("source", "blender", "blenfont", "BLF_translation.h") @@ -149,7 +152,10 @@ _str_whole_re = ( # 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")" PYGETTEXT_KEYWORDS = (() + tuple((r"{}\(\s*" + _msg_re + r"\s*\)").format(it) @@ -165,7 +171,11 @@ PYGETTEXT_KEYWORDS = (() + for it in ("BMO_error_raise",)) + 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 = ( diff --git a/release/scripts/modules/bl_i18n_utils/update_pot.py b/release/scripts/modules/bl_i18n_utils/update_pot.py index 51197b86678..ecb5d837a09 100755 --- a/release/scripts/modules/bl_i18n_utils/update_pot.py +++ b/release/scripts/modules/bl_i18n_utils/update_pot.py @@ -52,6 +52,7 @@ SRC_POTFILES = settings.FILE_NAME_SRC_POTFILES CONTEXT_DEFAULT = settings.CONTEXT_DEFAULT PYGETTEXT_ALLOWED_EXTS = settings.PYGETTEXT_ALLOWED_EXTS +PYGETTEXT_MAX_MULTI_CTXT = settings.PYGETTEXT_MAX_MULTI_CTXT 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 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: f = f.read() for srch in pygettexts: @@ -86,34 +112,23 @@ def check_file(path, rel_path, messages): line = pos = 0 while m: 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 += f[pos:m.start()].count('\n') - # And we are done for this item! - messages.setdefault((ctxt, msg), []).append(":".join((rel_path, str(line)))) + msg = d.get("msg_raw") + # 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() line += f[m.start():pos].count('\n') m = srch(f, pos) @@ -138,12 +153,12 @@ def py_xgettext(messages): rel_path = os.path.relpath(path, SOURCE_DIR) if rel_path in forbidden: continue - elif rel_path in forced: - forced.remove(rel_path) - check_file(path, rel_path, messages) - for path in forced: + elif rel_path not in forced: + forced.add(rel_path) + for rel_path in sorted(forced): + path = os.path.join(SOURCE_DIR, rel_path) if os.path.exists(path): - check_file(os.path.join(SOURCE_DIR, path), path, messages) + check_file(path, rel_path, messages) # Spell checking! |