def convert_file(src, dst): po = translate.storage.po.pofile.parsefile(src) with codecs.open(dst, "w", encoding=OUTPUT_ENC) as d: for unit in po.getunits(): id = unit.getid().replace('"', '\\"') #print id target = unit.gettarget().replace('"', '\\"') if not target: target = id string = u'"{0}" = "{1}";\n\n'.format(id, target) #print string d.write(string)
def remove_already_in_pot(strings, pot): """ Remove strings already in pot file """ ret = [] po = translate.storage.po.pofile.parsefile(pot) ids = [unit.getid() for unit in po.getunits()] for string in strings: if string not in ids: ret.append(string) return ret
def extract_po(data_xml_android, filename_po): """ Extract po data. Return a dictionnary : key:msgid, value:msgstr """ po = translate.storage.po.pofile.parsefile(filename_po) data = dict() for unit in po.getunits(): po_id = unit.getid() po_id = po_id.replace("\"", "\\\"") po_translation = unit.gettarget() for k, v in data_xml_android.iteritems(): if v == po_id: data[k] = po_translation return data