def save_content(self, handle): """Store content to file.""" # Fallback language lang = "LANG_ENGLISH" sublang = "SUBLANG_DEFAULT" # Keep existing language tags storage = self.store.rcfile if storage.lang: lang = storage.lang if storage.sublang: sublang = storage.sublang templatename = self.template_store.storefile if hasattr(templatename, "name"): templatename = templatename.name encoding = "utf-8" with open(templatename, "rb") as templatefile: bom = templatefile.read(2) if bom == codecs.BOM_UTF16_LE: encoding = "utf-16-le" templatefile.seek(0) convertor = rerc( templatefile, lang=lang, sublang=sublang, charset=encoding, ) outputrclines = convertor.convertstore(self.store) try: handle.write(outputrclines.encode(encoding)) except UnicodeEncodeError: handle.write(codecs.BOM_UTF16_LE) handle.write(outputrclines.encode("utf-16-le"))
def save_content(self, handle): """Store content to file.""" from translate.convert.po2rc import rerc # Fallback language lang = "LANG_ENGLISH" sublang = "SUBLANG_DEFAULT" # Keep existing language tags rcfile = self.store.rcfile if rcfile.lang: lang = rcfile.lang if rcfile.sublang: sublang = rcfile.sublang templatename = self.template_store.storefile if hasattr(templatename, "name"): templatename = templatename.name with open(templatename, "rb") as templatefile: convertor = rerc(templatefile, lang=lang, sublang=sublang) outputrclines = convertor.convertstore(self.store) try: handle.write(outputrclines.encode("cp1252")) except UnicodeEncodeError: handle.write(codecs.BOM_UTF16_LE) handle.write(outputrclines.encode("utf-16-le"))