bug 672031, pass locale to Checker, r=flod
Preparing to add plurals checker, we pass the locale from the
l10n file to the checker.
MozReview-Commit-ID: zIhVRqN9pY
--- a/compare_locales/checks.py
+++ b/compare_locales/checks.py
@@ -20,18 +20,19 @@ class Checker(object):
pattern = None
# if a check uses all reference entities, set this to True
needs_reference = False
@classmethod
def use(cls, file):
return cls.pattern.match(file.file)
- def __init__(self, extra_tests):
+ def __init__(self, extra_tests, locale=None):
self.extra_tests = extra_tests
+ self.locale = locale
self.reference = None
def check(self, refEnt, l10nEnt):
'''Given the reference and localized Entities, performs checks.
This is a generator yielding tuples of
- "warning" or "error", depending on what should be reported,
- tuple of line, column info for the error within the string
@@ -197,18 +198,18 @@ class DTDChecker(Checker):
needs_reference = True # to cast a wider net for known entity references
eref = re.compile('&(%s);' % DTDParser.Name)
tmpl = '''<!DOCTYPE elem [%s]>
<elem>%s</elem>
'''
xmllist = set(('amp', 'lt', 'gt', 'apos', 'quot'))
- def __init__(self, extra_tests):
- super(DTDChecker, self).__init__(extra_tests)
+ def __init__(self, extra_tests, locale=None):
+ super(DTDChecker, self).__init__(extra_tests, locale=locale)
self.processContent = False
if self.extra_tests is not None and 'android-dtd' in self.extra_tests:
self.processContent = True
self.__known_entities = None
def known_entities(self, refValue):
if self.__known_entities is None and self.reference is not None:
self.__known_entities = set()
@@ -482,14 +483,14 @@ class FluentChecker(Checker):
]
for attr in obsolete_attrs:
yield ('error', attr.span.start - l10n_entry.span.start,
'Obsolete attribute: ' + attr.id.name, 'fluent')
def getChecker(file, extra_tests=None):
if PropertiesChecker.use(file):
- return PropertiesChecker(extra_tests)
+ return PropertiesChecker(extra_tests, locale=file.locale)
if DTDChecker.use(file):
- return DTDChecker(extra_tests)
+ return DTDChecker(extra_tests, locale=file.locale)
if FluentChecker.use(file):
- return FluentChecker(extra_tests)
+ return FluentChecker(extra_tests, locale=file.locale)
return None