bug 672031, pass locale to Checker, r=flod
authorAxel Hecht <axel@pike.org>
Fri, 08 Dec 2017 15:30:26 +0100
changeset 395 f795b9834af7508d05f22061b87f73f4f03a39da
parent 394 f2a6a6f2cb6f295b19d438c8e890198630511d06
child 396 26f02b5a618aeb0577e3981a5207d462d148146b
push id136
push useraxel@mozilla.com
push dateWed, 13 Dec 2017 15:36:22 +0000
reviewersflod
bugs672031
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
compare_locales/checks.py
--- 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