How to use the polib.polib.pofile function in polib

To help you get started, we’ve selected a few polib examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github qooxdoo / qooxdoo / tool / pylib / generator / action / Locale.py View on Github external
def translationsFromPofiles(pofiles, pot, statsObj=None):
            for path in pofiles:
                self._console.debug("Reading file: %s" % path)

                # .po files are only read-accessed
                cacheId = "pofile-%s" % path
                po, _ = self._cache.read(cacheId, path, memory=True)
                if po == None:
                    po = polib.pofile(path)
                    self._cache.write(cacheId, po, memory=True)
                extractTranslations(pot, po, statsObj)
            return pot
github qooxdoo / qooxdoo / qooxdoo / tool / pylib / generator / action / Locale.py View on Github external
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] = Library.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: .po file from disk
            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()
github qooxdoo / qooxdoo / qooxdoo / tool / pylib / generator / action / Locale.py View on Github external
if len(pot) == 0:
                return {}
                
            self._console.debug("Processing translation: %s" % locale)
            self._console.indent()

            result = {}
            # loop through .po files
            for path in PoFiles[locale]:
                self._console.debug("Reading file: %s" % path)

                # .po files are only read-accessed
                cacheId = "pofile-%s" % path
                po, _ = self._cache.read(cacheId, path, memory=True)
                if po == None:
                    po = polib.pofile(path)
                    self._cache.write(cacheId, po, memory=True)
                extractTranslations(pot, po)

            poentries = pot.translated_entries()
            if addUntranslatedEntries:
                poentries.extend(pot.untranslated_entries())
            result.update(self.entriesToDict(poentries))

            self._console.debug("Formatting %s entries" % len(result))
            blocks[locale] = result
            self._console.outdent()

        return blocks
github qooxdoo / qooxdoo / qooxdoo / frontend / tool / pylib / generator / action / Locale.py View on Github external
if classes[classId]["namespace"] == namespace:
                content.append(classId)
                    
        self._console.debug("Compiling filter...")
        pot = self.getPotFile(content)
        pot.sort()

        self._console.debug("Updating translations...")
        self._console.indent()

        files = self._translation[namespace]
        for name in files:
            self._console.debug("Processing: %s" % name)

            entry = files[name]
            po = polib.pofile(entry["path"])
            po.merge(pot)
            po.sort()
            po.save(entry["path"])

        self._console.outdent()
        self._console.outdent()
github qooxdoo / qooxdoo / qooxdoo / frontend / tool / pylib / generator / action / Locale.py View on Github external
if not data.has_key(entry):
                        data[entry] = []

                    data[entry].append(files[entry]["path"])

        # Load po files
        blocks = {}
        for entry in data:
            self._console.debug("Processing translation: %s" % entry)
            self._console.indent()

            result = {}
            for path in data[entry]:
                self._console.debug("Reading file: %s" % path)

                po = polib.pofile(path)
                po.merge(pot)
                translated = po.translated_entries()
                
                result.update(self.entriesToDict(translated))

            self._console.debug("Formatting %s entries" % len(result))
            blocks[entry] = result
            self._console.outdent()

        return blocks
github qooxdoo / qooxdoo / tool / pylib / generator / action / Locale.py View on Github external
pof  = self.createPoFile()
                    f.write(self.applyEolStyle(str(pof)))
                    f.close()
                    allLocales[locale] = Library.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]

            try:
                po = polib.pofile(entry["path"])  # po: .po file from disk
                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)
                poString = self.applyEolStyle(poString)
                filetool.save(entry["path"], poString)
            except UnicodeDecodeError:
                self._console.nl()
                err_msg = "Likely charset declaration and file encoding mismatch (consider using utf-8) in:"
                self._console.error(err_msg + "\n%s" % entry["path"])
                self._console.nl()

            self._console.outdent()