bug 672031, factor plurals check in properties to distinct method, r=flod
MozReview-Commit-ID: 1viugE9s4QC
--- 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()