def configure(self, options, conf): super().configure(options, conf) # If no glade files were specified, find all of them if options.glade_file: glade_files = options.glade_file else: glade_files = testfilelist(lambda x: x.endswith('.glade')) # Parse all of the glade files log.info("Parsing glade files...") for glade_file in glade_files: self.glade_trees.append(etree.parse(glade_file)) if options.translate: log.info("Loading translations...") podicts = translate_all(options.podir) # Loop over each available language for lang, langmap in podicts.items(): self.translated_trees[lang] = [] # For each language, loop over the parsed glade files for tree in self.glade_trees: # Make a copy of the tree to translate and save it to # the list for this language tree = copy.deepcopy(tree) self.translated_trees[lang].append(tree) # Save the language as an attribute of the root of the tree tree.getroot().set("lang", lang) # Look for all properties with translatable=yes and translate them for translatable in tree.xpath( '//property[@translatable="yes"]'): try: xlated_text = langmap.get( translatable.text, context=translatable.get('context'))[0] # Add the untranslated text as an attribute to this node translatable.set("original_text", translatable.text) # Replace the actual text translatable.text = xlated_text except KeyError: # No translation available for this string in this language pass
def load_glade_trees_from_files(): """Load XML trees from glade files. :return: List of XML trees, as parsed by etree. """ trees = [] glade_files = testfilelist(lambda x: x.endswith('.glade')) if not glade_files: raise FileNotFoundError("Found no glade files to test.") # Parse all of the glade files log.info("Parsing glade files...") for glade_file in glade_files: trees.append(etree.parse(glade_file)) return trees
def configure(self, options, conf): super().configure(options, conf) # If no glade files were specified, find all of them if options.glade_file: glade_files = options.glade_file else: glade_files = testfilelist(lambda x: x.endswith('.glade')) # Parse all of the glade files log.info("Parsing glade files...") for glade_file in glade_files: self.glade_trees.append(etree.parse(glade_file)) if options.translate: log.info("Loading translations...") podicts = translate_all(options.podir) # Loop over each available language for lang, langmap in podicts.items(): self.translated_trees[lang] = [] # For each language, loop over the parsed glade files for tree in self.glade_trees: # Make a copy of the tree to translate and save it to # the list for this language tree = copy.deepcopy(tree) self.translated_trees[lang].append(tree) # Save the language as an attribute of the root of the tree tree.getroot().set("lang", lang) # Look for all properties with translatable=yes and translate them for translatable in tree.xpath('//property[@translatable="yes"]'): try: xlated_text = langmap.get(translatable.text, context=translatable.get('context'))[0] # Add the untranslated text as an attribute to this node translatable.set("original_text", translatable.text) # Replace the actual text translatable.text = xlated_text except KeyError: # No translation available for this string in this language pass
# Look for a "translatable=yes" attribute if ET.parse(checkfile).findall(".//*[@translatable='yes']"): potcheckfile = checkfile elif checkfile.endswith(".desktop.in"): # These are handled by intltool, make sure the .h version is present potcheckfile = checkfile + ".h" if not potcheckfile: return # Compute the path relative to top_srcdir potcheckfile = os.path.relpath(potcheckfile, os.environ["top_srcdir"]) if potcheckfile not in potlist: sys.stderr.write("%s not in POTFILES.in\n" % potcheckfile) success = False # Read in POTFILES.in, skip comments and blank lines POTFILES = set() with open(os.path.join(os.environ["top_srcdir"], "po", "POTFILES.in")) as f: for line in (line.strip() for line in f): if line and not line.startswith("#"): POTFILES.add(line) # Walk the source tree and look for files with translatable strings for testfile in testfilelist(): check_potfile(testfile, POTFILES) if not success: sys.exit(1)
if ET.parse(checkfile).findall(".//*[@translatable='yes']"): potcheckfile = checkfile + ".h" elif checkfile.endswith(".desktop.in"): # These are handled by intltool, make sure the .h version is present potcheckfile = checkfile + ".h" if not potcheckfile: return # Compute the path relative to top_srcdir potcheckfile = os.path.relpath(potcheckfile, os.environ["top_srcdir"]) if potcheckfile not in potlist: sys.stderr.write("%s not in POTFILES.in\n" % potcheckfile) success = False # Read in POTFILES.in, skip comments and blank lines POTFILES = set() with open(os.path.join(os.environ["top_srcdir"], "po", "POTFILES.in")) as f: for line in (line.strip() for line in f): if line and not line.startswith("#"): POTFILES.add(line) # Walk the source tree and look for files with translatable strings for testfile in testfilelist(): check_potfile(testfile, POTFILES) if not success: sys.exit(1)