def is_valid_base_for_new(base): ''' Checks whether base is valid. ''' try: pofile.parsefile(base) return True except Exception: return False
def create_new_file(cls, filename, language, base): """Handles creation of new translation file.""" store = pofile.parsefile(base) cls.untranslate_store(store, language) store.updateheader( last_translator='Automatically generated', plural_forms=language.get_plural_form(), language_team='none', ) store.savefile(filename)
def create_new_file(cls, filename, language, base): """Handle creation of new translation file.""" store = pofile.parsefile(base) cls.untranslate_store(store, language) store.updateheader( last_translator='Automatically generated', plural_forms=language.get_plural_form(), language_team='none', ) store.savefile(filename)
org.target = new.target org.markfuzzy(new.isfuzzy()) return org def rm_fuzzy_msgid_cmt(unit): src = unit.__str__() if (unit.isfuzzy()): return src lines = [] for line in src.split("\n"): if line[:2] == '#|': continue lines.append(line) return "\n".join(lines) if __name__ == '__main__': orgpo = sys.argv[1] newpo = sys.argv[2] org_units = pofile.parsefile(orgpo).units new_units = pofile.parsefile(newpo).units new_map = {} for unit in new_units: if unit.isobsolete() or not unit.source: continue new_map[(unit.getcontext(), unit.source)] = unit for org in org_units: new = new_map.get((org.getcontext(), org.source), None) if not new: print(org) continue merged = merge(org, new) print(rm_fuzzy_msgid_cmt(merged))
def make_pounit(self, src): from translate.storage.po import pofile po = self.make_po(src) return PoUnit(pofile.parsefile(po).units[0])
#!/usr/bin/env python # -*- coding: utf-8 -*- import sys from optparse import OptionParser from translate.storage.po import pofile from pounit import PoUnit from errata import Errata if __name__ == '__main__': parser = OptionParser() parser.add_option('-e', '--errata', action = 'store', type = 'string', dest = 'errata') (options, args) = parser.parse_args() if not options.errata: sys.exit('Oops! Specify your errata: -e <errata>') errata = Errata(options.errata) input = sys.stdin units = pofile.parsefile(input).units for unit in units: pounit = PoUnit(unit) if bool(pounit.target) and \ not pounit.isobsolete() and \ not pounit.iscredits(): pounit.fix_errata(errata.terms) print(pounit)