[Kimchi-devel] [PATCH 2/2] add a method to check the i18n strings are obsolete

shaohef at linux.vnet.ibm.com shaohef at linux.vnet.ibm.com
Tue Apr 8 01:39:18 UTC 2014


From: ShaoHe Feng <shaohef at 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 at linux.vnet.ibm.com>
Signed-off-by: ShaoHe Feng <shaohef at 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"
 
 
-- 
1.8.5.3




More information about the Kimchi-devel mailing list