Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Montagne <montagne29@wanadoo.fr>2013-10-17 13:02:03 +0400
committerBastien Montagne <montagne29@wanadoo.fr>2013-10-17 13:02:03 +0400
commit8ebd6cdc90b8f1cba387a7f343d09736ac655038 (patch)
tree84cd2ae6c888ac82512c44207cc8fa11c28bb7bd
parent96ffc9df2e4b1dd6ad1b4903bc27d516b2587731 (diff)
More complete handling of printf formatting in msgid/msgstr checks.
-rw-r--r--release/scripts/modules/bl_i18n_utils/settings.py10
-rw-r--r--release/scripts/modules/bl_i18n_utils/utils.py9
2 files changed, 15 insertions, 4 deletions
diff --git a/release/scripts/modules/bl_i18n_utils/settings.py b/release/scripts/modules/bl_i18n_utils/settings.py
index e40b067f552..dba5099607c 100644
--- a/release/scripts/modules/bl_i18n_utils/settings.py
+++ b/release/scripts/modules/bl_i18n_utils/settings.py
@@ -257,6 +257,16 @@ PYGETTEXT_KEYWORDS = (() +
for it in ("BLF_I18N_MSGID_MULTI_CTXT",))
)
+# Check printf mismatches between msgid and msgstr.
+CHECK_PRINTF_FORMAT = (
+ r"(?!<%)(?:%%)*%" # Begining, with handling for crazy things like '%%%%%s'
+ r"[-+#0]?" # Flags (note: do not add the ' ' (space) flag here, generates too much false positives!)
+ r"(?:\*|[0-9]+)?" # Width
+ r"(?:\.(?:\*|[0-9]+))?" # Precision
+ r"(?:[hljztL]|hh|ll)?" # Length
+ r"[tldiuoxXfFeEgGaAcspn]" # Specifiers (note we have Blender-specific %t and %l ones too)
+)
+
# Should po parser warn when finding a first letter not capitalized?
WARN_MSGID_NOT_CAPITALIZED = True
diff --git a/release/scripts/modules/bl_i18n_utils/utils.py b/release/scripts/modules/bl_i18n_utils/utils.py
index 1b6d65d89d0..181e47bc67b 100644
--- a/release/scripts/modules/bl_i18n_utils/utils.py
+++ b/release/scripts/modules/bl_i18n_utils/utils.py
@@ -446,10 +446,10 @@ class I18nMessages:
"""
ret = []
default_context = self.settings.DEFAULT_CONTEXT
- _format = re.compile("%[.0-9]*[tslfd]").findall
+ _format = re.compile(self.settings.CHECK_PRINTF_FORMAT).findall
done_keys = set()
- tmp = {}
rem = set()
+ tmp = {}
for key, msg in self.msgs.items():
msgctxt, msgid, msgstr = msg.msgctxt, msg.msgid, msg.msgstr
real_key = (msgctxt or default_context, msgid)
@@ -462,9 +462,10 @@ class I18nMessages:
elif fix:
tmp[real_key] = msg
done_keys.add(key)
- if '%' in msgid and msgstr and len(_format(msgid)) != len(_format(msgstr)):
+ if '%' in msgid and msgstr and _format(msgid) != _format(msgstr):
if not msg.is_fuzzy:
- ret.append("Error! msg's format entities are not matched in msgid and msgstr ({})".format(real_key))
+ ret.append("Error! msg's format entities are not matched in msgid and msgstr ({} / {})"
+ "".format(real_key, msgstr))
if fix:
msg.msgstr = ""
for k in rem: