From be60827916b487746576010873e9221a927daf0b Mon Sep 17 00:00:00 2001
From: Tristan Cavelier <tristan.cavelier@nexedi.com>
Date: Fri, 8 Jan 2016 10:55:54 -0500
Subject: [PATCH] erp5_administration: add tool to clean up Localizer messages

---
 .../extension.erp5.ERP5Administration.py      | 15 ++++++++++
 .../extension.erp5.ERP5Administration.xml     |  3 +-
 .../MessageCatalog_cleanUpMessageDict.xml     | 28 +++++++++++++++++++
 3 files changed, 45 insertions(+), 1 deletion(-)
 create mode 100644 bt5/erp5_administration/SkinTemplateItem/portal_skins/erp5_administration/MessageCatalog_cleanUpMessageDict.xml

diff --git a/bt5/erp5_administration/ExtensionTemplateItem/portal_components/extension.erp5.ERP5Administration.py b/bt5/erp5_administration/ExtensionTemplateItem/portal_components/extension.erp5.ERP5Administration.py
index 240c44863f..b3082c4360 100644
--- a/bt5/erp5_administration/ExtensionTemplateItem/portal_components/extension.erp5.ERP5Administration.py
+++ b/bt5/erp5_administration/ExtensionTemplateItem/portal_components/extension.erp5.ERP5Administration.py
@@ -117,6 +117,21 @@ def MessageCatalog_deleteNotTranslatedMessageDict(self):
     del(self._messages[k])
   return len(not_translated_message_dict.keys())
 
+def MessageCatalog_cleanUpMessageDict(self):
+  """
+    Cleans up translation dictionnaries by removing empty values
+    and deleting entries without any translation from the Localizer's
+    MessageCatalog instance messages.
+  """
+  count = 0
+  for k,v in self._messages.items():
+    for lang, translation in v.items():
+      if len(translation) == 0 or translation == k:
+        del self._messages[k][lang]
+    if len(v) == 0:
+      del self._messages[k]
+      count += 1
+  return count
 
 def checkConversionToolAvailability(self):
   """
diff --git a/bt5/erp5_administration/ExtensionTemplateItem/portal_components/extension.erp5.ERP5Administration.xml b/bt5/erp5_administration/ExtensionTemplateItem/portal_components/extension.erp5.ERP5Administration.xml
index 2b2f670221..f08449a151 100644
--- a/bt5/erp5_administration/ExtensionTemplateItem/portal_components/extension.erp5.ERP5Administration.xml
+++ b/bt5/erp5_administration/ExtensionTemplateItem/portal_components/extension.erp5.ERP5Administration.xml
@@ -46,7 +46,8 @@
             <key> <string>text_content_warning_message</string> </key>
             <value>
               <tuple>
-                <string>W:   88,   29: map/filter on lambda could be replaced by comprehension (deprecated-lambda)</string>
+                <string>W:106, 29: map/filter on lambda could be replaced by comprehension (deprecated-lambda)</string>
+                <string>W:156,  2: No exception type(s) specified (bare-except)</string>
               </tuple>
             </value>
         </item>
diff --git a/bt5/erp5_administration/SkinTemplateItem/portal_skins/erp5_administration/MessageCatalog_cleanUpMessageDict.xml b/bt5/erp5_administration/SkinTemplateItem/portal_skins/erp5_administration/MessageCatalog_cleanUpMessageDict.xml
new file mode 100644
index 0000000000..a43b4db81f
--- /dev/null
+++ b/bt5/erp5_administration/SkinTemplateItem/portal_skins/erp5_administration/MessageCatalog_cleanUpMessageDict.xml
@@ -0,0 +1,28 @@
+<?xml version="1.0"?>
+<ZopeData>
+  <record id="1" aka="AAAAAAAAAAE=">
+    <pickle>
+      <global name="ExternalMethod" module="Products.ExternalMethod.ExternalMethod"/>
+    </pickle>
+    <pickle>
+      <dictionary>
+        <item>
+            <key> <string>_function</string> </key>
+            <value> <string>MessageCatalog_cleanUpMessageDict</string> </value>
+        </item>
+        <item>
+            <key> <string>_module</string> </key>
+            <value> <string>ERP5Administration</string> </value>
+        </item>
+        <item>
+            <key> <string>id</string> </key>
+            <value> <string>MessageCatalog_cleanUpMessageDict</string> </value>
+        </item>
+        <item>
+            <key> <string>title</string> </key>
+            <value> <string>Cleans up translation dictionnaries by removing empty values and deleting entries without any translation from the Localizer\'s MessageCatalog instance messages.</string> </value>
+        </item>
+      </dictionary>
+    </pickle>
+  </record>
+</ZopeData>
-- 
2.30.9