
Reviewed-by: Daniel Barboza <danielhb@linux.vnet.ibm.com> On 04/07/2014 10:39 PM, shaohef@linux.vnet.ibm.com wrote:
From: ShaoHe Feng <shaohef@linux.vnet.ibm.com>
There are some i18n strings are no longer in use in source code. But they are still remain in i18n.py.
We should add a mechanism to check the obsolete i18n strings.
Signed-off-by: Zhou Zheng Sheng <zhshzhou@linux.vnet.ibm.com> Signed-off-by: ShaoHe Feng <shaohef@linux.vnet.ibm.com> --- contrib/check_i18n.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)
diff --git a/contrib/check_i18n.py b/contrib/check_i18n.py index e3c2b8c..e9eab6e 100755 --- a/contrib/check_i18n.py +++ b/contrib/check_i18n.py @@ -45,6 +45,25 @@ def check_string_formatting(messages): exit(1)
+def check_obsolete_messages(path, messages): + def find_message_key(path, k): + for root, dirs, files in os.walk(path): + for f in files: + fname = os.path.join(root, f) + if (not fname.endswith("i18n.py") and fname.endswith(".py") + or fname.endswith(".json")): + with open(fname) as f: + string = "".join(f.readlines()) + if k in string: + return True + return False + + for k in messages.iterkeys(): + if not find_message_key(path, k): + print " %s is obsolete, it is no longer in use" % k + exit(1) + + def main(): files = [] for v in sys.argv[1:]: @@ -54,6 +73,7 @@ def main(): for f in files: messages = load_i18n_module(f).messages check_string_formatting(messages) + check_obsolete_messages(os.path.dirname(f), messages) print "Checking for invalid i18n string successfully"