示例#1
0
    def run_filters(self, unit, categorised=False):
        """Make some optimizations before running individual filters in
        `run_test`.
        """
        self.str1 = data.normalized_unicode(unit.source) or u''
        self.str2 = data.normalized_unicode(unit.target) or u''

        self.language_code = unit.store.translation_project.language.code

        return super(ENChecker, self).run_filters(unit, categorised)
示例#2
0
文件: checks.py 项目: paxswill/pootle
    def run_filters(self, unit, categorised=False):
        """Make some optimizations before running individual filters in
        `run_test`.
        """
        self.str1 = data.normalized_unicode(unit.source) or u''
        self.str2 = data.normalized_unicode(unit.target) or u''

        self.language_code = unit.store.translation_project.language.code

        return super(ENChecker, self).run_filters(unit, categorised)
示例#3
0
文件: checks.py 项目: ratanasoth/zing
    def run_filters(self, unit, categorised=False):
        """Make some optimizations before running individual filters in
        `run_test`.
        """
        self.str1 = data.normalized_unicode(unit.source) or u''
        self.str2 = data.normalized_unicode(unit.target) or u''

        # FIXME: avoid this
        from pootle.core.checks.checker import CheckableUnit
        if isinstance(unit, CheckableUnit):
            self.language_code = unit.language_code
        else:
            self.language_code = unit.store.translation_project.language.code

        return super(ENChecker, self).run_filters(unit, categorised)
示例#4
0
文件: checks.py 项目: ratanasoth/zing
def run_given_filters(checker, unit, check_names=None):
    """Run all the tests in this suite.

    :rtype: Dictionary
    :return: Content of the dictionary is as follows::

       {'testname': {
           'message': message_or_exception,
           'category': failure_category
        }}

    Do some optimisation by caching some data of the unit for the
    benefit of :meth:`~TranslationChecker.run_test`.
    """
    if check_names is None:
        check_names = []

    checker.str1 = data.normalized_unicode(unit.source) or u""
    checker.str2 = data.normalized_unicode(unit.target) or u""
    checker.language_code = unit.language_code  # XXX: comes from `CheckableUnit`
    checker.hasplural = unit.hasplural()
    checker.locations = unit.getlocations()

    checker.results_cache = {}
    failures = {}

    for functionname in check_names:
        filterfunction = getattr(checker, functionname, None)

        # This filterfunction may only be defined on another checker if
        # using TeeChecker
        if filterfunction is None:
            continue

        filtermessage = filterfunction.__doc__

        try:
            filterresult = checker.run_test(filterfunction, unit)
        except checks.FilterFailure, e:
            filterresult = False
            filtermessage = unicode(e)
        except Exception, e:
            if checker.errorhandler is None:
                raise ValueError("error in filter %s: %r, %r, %s" %
                                 (functionname, unit.source, unit.target, e))
            else:
                filterresult = checker.errorhandler(functionname, unit.source,
                                                    unit.target, e)
示例#5
0
def run_given_filters(checker, unit, check_names=None):
    """Run all the tests in this suite.

    :rtype: Dictionary
    :return: Content of the dictionary is as follows::

       {'testname': {
           'message': message_or_exception,
           'category': failure_category
        }}

    Do some optimisation by caching some data of the unit for the
    benefit of :meth:`~TranslationChecker.run_test`.
    """
    if check_names is None:
        check_names = []

    checker.str1 = data.normalized_unicode(unit.source) or u""
    checker.str2 = data.normalized_unicode(unit.target) or u""
    checker.language_code = unit.language_code  # XXX: comes from `CheckableUnit`
    checker.hasplural = unit.hasplural()
    checker.locations = unit.getlocations()

    checker.results_cache = {}
    failures = {}

    for functionname in check_names:
        filterfunction = getattr(checker, functionname, None)

        # This filterfunction may only be defined on another checker if
        # using TeeChecker
        if filterfunction is None:
            continue

        filtermessage = filterfunction.__doc__

        try:
            filterresult = checker.run_test(filterfunction, unit)
        except checks.FilterFailure, e:
            filterresult = False
            filtermessage = unicode(e)
        except Exception, e:
            if checker.errorhandler is None:
                raise ValueError("error in filter %s: %r, %r, %s" %
                                 (functionname, unit.source, unit.target, e))
            else:
                filterresult = checker.errorhandler(functionname, unit.source,
                                                    unit.target, e)
示例#6
0
def quality_check(original, string, locale, ignore):
    """Check for obvious errors like blanks and missing interpunction."""

    if not ignore:
        original = lang_data.normalized_unicode(original)
        string = lang_data.normalized_unicode(string)

        unit = storage_base.TranslationUnit(original)
        unit.target = string
        checker = checks.StandardChecker(checkerconfig=checks.CheckerConfig(
            targetlanguage=locale.code))

        warnings = checker.run_filters(unit)
        if warnings:

            # https://github.com/translate/pootle/
            check_names = {
                'accelerators': 'Accelerators',
                'acronyms': 'Acronyms',
                'blank': 'Blank',
                'brackets': 'Brackets',
                'compendiumconflicts': 'Compendium conflict',
                'credits': 'Translator credits',
                'doublequoting': 'Double quotes',
                'doublespacing': 'Double spaces',
                'doublewords': 'Repeated word',
                'emails': 'E-mail',
                'endpunc': 'Ending punctuation',
                'endwhitespace': 'Ending whitespace',
                'escapes': 'Escapes',
                'filepaths': 'File paths',
                'functions': 'Functions',
                'gconf': 'GConf values',
                'kdecomments': 'Old KDE comment',
                'long': 'Long',
                'musttranslatewords': 'Must translate words',
                'newlines': 'Newlines',
                'nplurals': 'Number of plurals',
                'notranslatewords': 'Don\'t translate words',
                'numbers': 'Numbers',
                'options': 'Options',
                'printf': 'printf()',
                'puncspacing': 'Punctuation spacing',
                'purepunc': 'Pure punctuation',
                'sentencecount': 'Number of sentences',
                'short': 'Short',
                'simplecaps': 'Simple capitalization',
                'simpleplurals': 'Simple plural(s)',
                'singlequoting': 'Single quotes',
                'startcaps': 'Starting capitalization',
                'startpunc': 'Starting punctuation',
                'startwhitespace': 'Starting whitespace',
                'tabs': 'Tabs',
                'unchanged': 'Unchanged',
                'untranslated': 'Untranslated',
                'urls': 'URLs',
                'validchars': 'Valid characters',
                'variables': 'Placeholders',
                'xmltags': 'XML tags',
            }

            warnings_array = []
            for key in warnings.keys():
                warning = check_names.get(key, key)
                warnings_array.append(warning)

            return HttpResponse(json.dumps({
                'warnings': warnings_array,
            }),
                                mimetype='application/json')
示例#7
0
def quality_check(original, string, locale, ignore):
    """Check for obvious errors like blanks and missing interpunction."""

    if not ignore:
        original = lang_data.normalized_unicode(original)
        string = lang_data.normalized_unicode(string)

        unit = storage_base.TranslationUnit(original)
        unit.target = string
        checker = checks.StandardChecker(
            checkerconfig=checks.CheckerConfig(targetlanguage=locale.code))

        warnings = checker.run_filters(unit)
        if warnings:

            # https://github.com/translate/pootle/
            check_names = {
                'accelerators': 'Accelerators',
                'acronyms': 'Acronyms',
                'blank': 'Blank',
                'brackets': 'Brackets',
                'compendiumconflicts': 'Compendium conflict',
                'credits': 'Translator credits',
                'doublequoting': 'Double quotes',
                'doublespacing': 'Double spaces',
                'doublewords': 'Repeated word',
                'emails': 'E-mail',
                'endpunc': 'Ending punctuation',
                'endwhitespace': 'Ending whitespace',
                'escapes': 'Escapes',
                'filepaths': 'File paths',
                'functions': 'Functions',
                'gconf': 'GConf values',
                'kdecomments': 'Old KDE comment',
                'long': 'Long',
                'musttranslatewords': 'Must translate words',
                'newlines': 'Newlines',
                'nplurals': 'Number of plurals',
                'notranslatewords': 'Don\'t translate words',
                'numbers': 'Numbers',
                'options': 'Options',
                'printf': 'printf()',
                'puncspacing': 'Punctuation spacing',
                'purepunc': 'Pure punctuation',
                'sentencecount': 'Number of sentences',
                'short': 'Short',
                'simplecaps': 'Simple capitalization',
                'simpleplurals': 'Simple plural(s)',
                'singlequoting': 'Single quotes',
                'startcaps': 'Starting capitalization',
                'startpunc': 'Starting punctuation',
                'startwhitespace': 'Starting whitespace',
                'tabs': 'Tabs',
                'unchanged': 'Unchanged',
                'untranslated': 'Untranslated',
                'urls': 'URLs',
                'validchars': 'Valid characters',
                'variables': 'Placeholders',
                'xmltags': 'XML tags',
            }

            warnings_array = []
            for key in warnings.keys():
                warning = check_names.get(key, key)
                warnings_array.append(warning)

            return HttpResponse(json.dumps({
                'warnings': warnings_array,
            }), content_type='application/json')
示例#8
0
def run_checks(original, string, locale_code, disabled_checks=None):
    """Check for obvious errors like blanks and missing interpunction."""
    original = lang_data.normalized_unicode(original)
    string = lang_data.normalized_unicode(string)
    disabled_checks = disabled_checks or []

    unit = storage_base.TranslationUnit(original)
    unit.target = string
    checker = checks.StandardChecker(
        checkerconfig=checks.CheckerConfig(targetlanguage=locale_code),
        excludefilters=disabled_checks,
    )

    warnings = checker.run_filters(unit)

    if not warnings:
        return {}

    check_names = {
        "accelerators": "Accelerators",
        "blank": "Blank",
        "brackets": "Brackets",
        "compendiumconflicts": "Compendium conflict",
        "credits": "Translator credits",
        "doublequoting": "Double quotes",
        "doublespacing": "Double spaces",
        "doublewords": "Repeated word",
        "emails": "E-mail",
        "endpunc": "Ending punctuation",
        "endwhitespace": "Ending whitespace",
        "escapes": "Escapes",
        "filepaths": "File paths",
        "functions": "Functions",
        "long": "Long",
        "musttranslatewords": "Must translate words",
        "newlines": "Newlines",
        "nplurals": "Number of plurals",
        "notranslatewords": "Don't translate words",
        "numbers": "Numbers",
        "options": "Options",
        "printf": "Printf format string mismatch",
        "puncspacing": "Punctuation spacing",
        "purepunc": "Pure punctuation",
        "sentencecount": "Number of sentences",
        "short": "Short",
        "simplecaps": "Simple capitalization",
        "simpleplurals": "Simple plural(s)",
        "singlequoting": "Single quotes",
        "startcaps": "Starting capitalization",
        "startpunc": "Starting punctuation",
        "startwhitespace": "Starting whitespace",
        "tabs": "Tabs",
        "unchanged": "Unchanged",
        "urls": "URLs",
        "validchars": "Valid characters",
        "variables": "Placeholders",
        "xmltags": "XML tags",
    }

    warnings_array = []
    for key in warnings.keys():
        warning = check_names.get(key, key)
        warnings_array.append(warning)

    return {
        "ttWarnings": warnings_array,
    }
示例#9
0
def run_checks(original, string, locale_code, disabled_checks=None):
    """Check for obvious errors like blanks and missing interpunction."""
    original = lang_data.normalized_unicode(original)
    string = lang_data.normalized_unicode(string)
    disabled_checks = disabled_checks or []

    unit = storage_base.TranslationUnit(original)
    unit.target = string
    checker = checks.StandardChecker(
        checkerconfig=checks.CheckerConfig(targetlanguage=locale_code),
        excludefilters=disabled_checks)

    warnings = checker.run_filters(unit)

    if not warnings:
        return {}

    check_names = {
        'accelerators': 'Accelerators',
        'blank': 'Blank',
        'brackets': 'Brackets',
        'compendiumconflicts': 'Compendium conflict',
        'credits': 'Translator credits',
        'doublequoting': 'Double quotes',
        'doublespacing': 'Double spaces',
        'doublewords': 'Repeated word',
        'emails': 'E-mail',
        'endpunc': 'Ending punctuation',
        'endwhitespace': 'Ending whitespace',
        'escapes': 'Escapes',
        'filepaths': 'File paths',
        'functions': 'Functions',
        'long': 'Long',
        'musttranslatewords': 'Must translate words',
        'newlines': 'Newlines',
        'nplurals': 'Number of plurals',
        'notranslatewords': 'Don\'t translate words',
        'numbers': 'Numbers',
        'options': 'Options',
        'printf': 'Printf format string mismatch',
        'puncspacing': 'Punctuation spacing',
        'purepunc': 'Pure punctuation',
        'sentencecount': 'Number of sentences',
        'short': 'Short',
        'simplecaps': 'Simple capitalization',
        'simpleplurals': 'Simple plural(s)',
        'singlequoting': 'Single quotes',
        'startcaps': 'Starting capitalization',
        'startpunc': 'Starting punctuation',
        'startwhitespace': 'Starting whitespace',
        'tabs': 'Tabs',
        'unchanged': 'Unchanged',
        'untranslated': 'Untranslated',
        'urls': 'URLs',
        'validchars': 'Valid characters',
        'variables': 'Placeholders',
        'xmltags': 'XML tags',
    }

    warnings_array = []
    for key in warnings.keys():
        warning = check_names.get(key, key)
        warnings_array.append(warning)

    return {
        'ttWarnings': warnings_array,
    }
示例#10
0
def strprep(str1, str2, message=None):
    return data.normalized_unicode(str1), data.normalized_unicode(str2), data.normalized_unicode(message)
示例#11
0
def run_checks(original, string, locale_code, disabled_checks=None):
    """Check for obvious errors like blanks and missing interpunction."""
    original = lang_data.normalized_unicode(original)
    string = lang_data.normalized_unicode(string)
    disabled_checks = disabled_checks or []

    unit = storage_base.TranslationUnit(original)
    unit.target = string
    checker = checks.StandardChecker(
        checkerconfig=checks.CheckerConfig(targetlanguage=locale_code),
        excludefilters=disabled_checks
    )

    warnings = checker.run_filters(unit)

    if not warnings:
        return {}

    check_names = {
        'accelerators': 'Accelerators',
        'blank': 'Blank',
        'brackets': 'Brackets',
        'compendiumconflicts': 'Compendium conflict',
        'credits': 'Translator credits',
        'doublequoting': 'Double quotes',
        'doublespacing': 'Double spaces',
        'doublewords': 'Repeated word',
        'emails': 'E-mail',
        'endpunc': 'Ending punctuation',
        'endwhitespace': 'Ending whitespace',
        'escapes': 'Escapes',
        'filepaths': 'File paths',
        'functions': 'Functions',
        'long': 'Long',
        'musttranslatewords': 'Must translate words',
        'newlines': 'Newlines',
        'nplurals': 'Number of plurals',
        'notranslatewords': 'Don\'t translate words',
        'numbers': 'Numbers',
        'options': 'Options',
        'printf': 'Printf format string mismatch',
        'puncspacing': 'Punctuation spacing',
        'purepunc': 'Pure punctuation',
        'sentencecount': 'Number of sentences',
        'short': 'Short',
        'simplecaps': 'Simple capitalization',
        'simpleplurals': 'Simple plural(s)',
        'singlequoting': 'Single quotes',
        'startcaps': 'Starting capitalization',
        'startpunc': 'Starting punctuation',
        'startwhitespace': 'Starting whitespace',
        'tabs': 'Tabs',
        'unchanged': 'Unchanged',
        'urls': 'URLs',
        'validchars': 'Valid characters',
        'variables': 'Placeholders',
        'xmltags': 'XML tags',
    }

    warnings_array = []
    for key in warnings.keys():
        warning = check_names.get(key, key)
        warnings_array.append(warning)

    return {
        'ttWarnings': warnings_array,
    }
示例#12
0
文件: utils.py 项目: jotes/pontoon
def quality_check(original, string, locale, ignore):
    """Check for obvious errors like blanks and missing interpunction."""

    if not ignore:
        original = lang_data.normalized_unicode(original)
        string = lang_data.normalized_unicode(string)

        unit = storage_base.TranslationUnit(original)
        unit.target = string
        checker = checks.StandardChecker(checkerconfig=checks.CheckerConfig(targetlanguage=locale.code))

        warnings = checker.run_filters(unit)
        if warnings:

            # https://github.com/translate/pootle/
            check_names = {
                "accelerators": "Accelerators",
                "acronyms": "Acronyms",
                "blank": "Blank",
                "brackets": "Brackets",
                "compendiumconflicts": "Compendium conflict",
                "credits": "Translator credits",
                "doublequoting": "Double quotes",
                "doublespacing": "Double spaces",
                "doublewords": "Repeated word",
                "emails": "E-mail",
                "endpunc": "Ending punctuation",
                "endwhitespace": "Ending whitespace",
                "escapes": "Escapes",
                "filepaths": "File paths",
                "functions": "Functions",
                "gconf": "GConf values",
                "kdecomments": "Old KDE comment",
                "long": "Long",
                "musttranslatewords": "Must translate words",
                "newlines": "Newlines",
                "nplurals": "Number of plurals",
                "notranslatewords": "Don't translate words",
                "numbers": "Numbers",
                "options": "Options",
                "printf": "printf()",
                "puncspacing": "Punctuation spacing",
                "purepunc": "Pure punctuation",
                "sentencecount": "Number of sentences",
                "short": "Short",
                "simplecaps": "Simple capitalization",
                "simpleplurals": "Simple plural(s)",
                "singlequoting": "Single quotes",
                "startcaps": "Starting capitalization",
                "startpunc": "Starting punctuation",
                "startwhitespace": "Starting whitespace",
                "tabs": "Tabs",
                "unchanged": "Unchanged",
                "untranslated": "Untranslated",
                "urls": "URLs",
                "validchars": "Valid characters",
                "variables": "Placeholders",
                "xmltags": "XML tags",
            }

            warnings_array = []
            for key in warnings.keys():
                warning = check_names.get(key, key)
                warnings_array.append(warning)

            return HttpResponse(json.dumps({"warnings": warnings_array}), content_type="application/json")