def updateTranslations(self, namespace, translationDir, localesList=None): self._console.info("Updating namespace: %s" % namespace) self._console.indent() self._console.debug("Looking up relevant class files...") classList = [] classes = self._classes for classId in classes: if classes[classId]["namespace"] == namespace: classList.append(classId) self._console.debug("Compiling filter...") pot = self.getPotFile(classList) pot.sort() allfiles = self._translation[namespace] if localesList == None: filenames = allfiles.keys() else: filenames = localesList for name in filenames: if name not in allfiles: path = os.path.join(translationDir, name + ".po") f = open(path, 'w') # create stanza file pof = self.createPoFile() f.write(str(pof)) f.close() allfiles[name] = LibraryPath.translationEntry(name, path, namespace) self._console.info("Updating %d translations..." % len(filenames)) self._console.indent() for name in filenames: self._console.debug("Processing: %s" % name) entry = allfiles[name] po = polib.pofile(entry["path"]) po.merge(pot) po.sort() po.save(entry["path"]) self._console.outdent() self._console.outdent()
def updateTranslations(self, namespace, translationDir, localesList=None): def parsePOEntryStrings(poset): for poentry in poset: poentry.msgid = self.parseAsUnicodeString(poentry.msgid) poentry.msgid_plural = self.parseAsUnicodeString(poentry.msgid_plural) if poentry.msgstr_plural: for pos in poentry.msgstr_plural: poentry.msgstr_plural[pos] = self.parseAsUnicodeString(poentry.msgstr_plural[pos]) def unescapeMsgIds(poset): for poentry in poset: if poentry.msgid.find(r'\\') > -1: poentry.msgid = self.recoverBackslashEscapes(poentry.msgid) self._console.info("Updating namespace: %s" % namespace) self._console.indent() self._console.debug("Looking up relevant class files...") classList = [] classes = self._classes for classId in classes: if classes[classId]["namespace"] == namespace: classList.append(classId) self._console.debug("Compiling filter...") pot = self.getPotFile(classList) pot.sort() allLocales = self._translation[namespace] if localesList == None: selectedLocales = allLocales.keys() else: selectedLocales = localesList for locale in selectedLocales: if locale not in allLocales: path = os.path.join(translationDir, locale + ".po") f = open(path, 'w') # create stanza file pof = self.createPoFile() f.write(str(pof)) f.close() allLocales[locale] = LibraryPath.translationEntry(locale, path, namespace) self._console.info("Updating %d translations..." % len(selectedLocales)) self._console.indent() for locale in selectedLocales: self._console.debug("Processing: %s" % locale) self._console.indent() entry = allLocales[locale] po = polib.pofile(entry["path"]) po.merge(pot) po.sort() self._console.debug("Percent translated: %d" % (po.percent_translated(),)) #po.save(entry["path"]) poString = str(po) #poString = self.recoverBackslashEscapes(poString) filetool.save(entry["path"], poString) self._console.outdent() self._console.outdent() self._console.outdent()