bug 672031, factor plurals check in properties to distinct method, r=flod
authorAxel Hecht <axel@pike.org>
Fri, 08 Dec 2017 15:36:41 +0100
changeset 396 26f02b5a618aeb0577e3981a5207d462d148146b
parent 395 f795b9834af7508d05f22061b87f73f4f03a39da
child 397 470deccb6926ebffac19dcbdd144ee9edf0a5c60
push id136
push useraxel@mozilla.com
push dateWed, 13 Dec 2017 15:36:22 +0000
reviewersflod
bugs672031
bug 672031, factor plurals check in properties to distinct method, r=flod MozReview-Commit-ID: 1viugE9s4QC
compare_locales/checks.py
--- a/compare_locales/checks.py
+++ b/compare_locales/checks.py
@@ -69,31 +69,18 @@ class PropertiesChecker(Checker):
         '''Test for the different variable formats.
         '''
         refValue, l10nValue = refEnt.val, l10nEnt.val
         refSpecs = None
         # check for PluralForm.jsm stuff, should have the docs in the
         # comment
         if (refEnt.pre_comment
                 and 'Localization_and_Plurals' in refEnt.pre_comment.all):
-            # For plurals, common variable pattern is #1. Try that.
-            pats = set(int(m.group(1)) for m in re.finditer('#([0-9]+)',
-                                                            refValue))
-            if len(pats) == 0:
-                return
-            lpats = set(int(m.group(1)) for m in re.finditer('#([0-9]+)',
-                                                             l10nValue))
-            if pats - lpats:
-                yield ('warning', 0, 'not all variables used in l10n',
-                       'plural')
-                return
-            if lpats - pats:
-                yield ('error', 0, 'unreplaced variables in l10n',
-                       'plural')
-                return
+            for msg_tuple in self.check_plural(refValue, l10nValue):
+                yield msg_tuple
             return
         # check for lost escapes
         raw_val = l10nEnt.raw_val
         for m in PropertiesEntity.escape.finditer(raw_val):
             if m.group('single') and \
                m.group('single') not in PropertiesEntity.known_escapes:
                 yield ('warning', m.start(),
                        'unknown escape sequence, \\' + m.group('single'),
@@ -102,16 +89,34 @@ class PropertiesChecker(Checker):
             refSpecs = self.getPrintfSpecs(refValue)
         except PrintfException:
             refSpecs = []
         if refSpecs:
             for t in self.checkPrintf(refSpecs, l10nValue):
                 yield t
             return
 
+    def check_plural(self, refValue, l10nValue):
+        '''Check for the stringbundle plurals logic.
+        The common variable pattern is #1.
+        '''
+        pats = set(int(m.group(1)) for m in re.finditer('#([0-9]+)',
+                                                        refValue))
+        if len(pats) == 0:
+            return
+        lpats = set(int(m.group(1)) for m in re.finditer('#([0-9]+)',
+                                                         l10nValue))
+        if pats - lpats:
+            yield ('warning', 0, 'not all variables used in l10n',
+                   'plural')
+            return
+        if lpats - pats:
+            yield ('error', 0, 'unreplaced variables in l10n',
+                   'plural')
+
     def checkPrintf(self, refSpecs, l10nValue):
         try:
             l10nSpecs = self.getPrintfSpecs(l10nValue)
         except PrintfException, e:
             yield ('error', e.pos, e.msg, 'printf')
             return
         if refSpecs != l10nSpecs:
             sm = SequenceMatcher()