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

shaohef at linux.vnet.ibm.com shaohef at linux.vnet.ibm.com
Mon Apr 14 05:38:42 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 bb33ddb..aca5751 100755
--- a/contrib/check_i18n.py
+++ b/contrib/check_i18n.py
@@ -50,11 +50,31 @@ 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():
     print "Checking for invalid i18n string..."
     for f in sys.argv[1:]:
         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