def build_checkerconfig(options): """Prepare the checker config from the given options. This is mainly factored out for the sake of unit tests.""" checkerconfig = checks.CheckerConfig(targetlanguage=options.targetlanguage) if options.notranslatefile: options.notranslatefile = os.path.expanduser(options.notranslatefile) if not os.path.exists(options.notranslatefile): self.error("notranslatefile %r does not exist" % options.notranslatefile) notranslatewords = [ line.strip() for line in open(options.notranslatefile).readlines() ] notranslatewords = dict.fromkeys([key for key in notranslatewords]) checkerconfig.notranslatewords.update(notranslatewords) if options.musttranslatefile: options.musttranslatefile = os.path.expanduser( options.musttranslatefile) if not os.path.exists(options.musttranslatefile): self.error("musttranslatefile %r does not exist" % options.musttranslatefile) musttranslatewords = [ line.strip() for line in open(options.musttranslatefile).readlines() ] musttranslatewords = dict.fromkeys([key for key in musttranslatewords]) checkerconfig.musttranslatewords.update(musttranslatewords) if options.validcharsfile: options.validcharsfile = os.path.expanduser(options.validcharsfile) if not os.path.exists(options.validcharsfile): self.error("validcharsfile %r does not exist" % options.validcharsfile) validchars = open(options.validcharsfile).read() checkerconfig.updatevalidchars(validchars) return checkerconfig
def run(self): """parses the arguments, and runs recursiveprocess with the resulting options""" (options, args) = self.parse_args() if options.filterclass is None: checkerclasses = [ checks.StandardChecker, checks.StandardUnitChecker ] else: checkerclasses = [options.filterclass, checks.StandardUnitChecker] checkerconfig = checks.CheckerConfig( targetlanguage=options.targetlanguage) if options.notranslatefile: options.notranslatefile = os.path.expanduser( options.notranslatefile) if not os.path.exists(options.notranslatefile): self.error("notranslatefile %r does not exist" % options.notranslatefile) notranslatewords = [ line.strip() for line in open(options.notranslatefile).readlines() ] notranslatewords = dict.fromkeys([key for key in notranslatewords]) checkerconfig.notranslatewords.update(notranslatewords) if options.musttranslatefile: options.musttranslatefile = os.path.expanduser( options.musttranslatefile) if not os.path.exists(options.musttranslatefile): self.error("musttranslatefile %r does not exist" % options.musttranslatefile) musttranslatewords = [ line.strip() for line in open(options.musttranslatefile).readlines() ] musttranslatewords = dict.fromkeys( [key for key in musttranslatewords]) checkerconfig.musttranslatewords.update(musttranslatewords) if options.validcharsfile: options.validcharsfile = os.path.expanduser(options.validcharsfile) if not os.path.exists(options.validcharsfile): self.error("validcharsfile %r does not exist" % options.validcharsfile) validchars = open(options.validcharsfile).read() checkerconfig.updatevalidchars(validchars) options.checkfilter = pocheckfilter(options, checkerclasses, checkerconfig) if not options.checkfilter.checker.combinedfilters: self.error("No valid filters were specified") options.inputformats = self.inputformats options.outputoptions = self.outputoptions self.usepsyco(options) if options.listfilters: print options.checkfilter.getfilterdocs() else: self.recursiveprocess(options)
def filter(self, translationstore, checkerconfig=None, cmdlineoptions=None): """Helper that passes a translations store through a filter, and returns the resulting store.""" if cmdlineoptions is None: cmdlineoptions = [] options, args = pofilter.cmdlineparser().parse_args([self.filename] + cmdlineoptions) checkerclasses = [checks.StandardChecker, checks.StandardUnitChecker] if checkerconfig is None: checkerconfig = checks.CheckerConfig() checkfilter = pofilter.pocheckfilter(options, checkerclasses, checkerconfig) tofile = checkfilter.filterfile(translationstore) return tofile
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')
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, }
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, }