def findLibResources(self, lib, filter=None): def getCache(lib): cacheId = "resinlib-%s" % lib._path liblist = self._genobj._cache.read(cacheId, dependsOn=None, memory=True) return liblist, cacheId def isSkipFile(f): if [x for x in map(lambda x: re.search(x, f), ignoredFiles) if x!=None]: return True else: return False # - Main -------------------------------------------------------------- cacheList = [] # to poss. populate cache cacheId = "" # will be filled in getCache() ignoredFiles = [r'\.meta$',] # files not considered as resources # create wrapper object libObj = Library(lib, self._genobj._console) # retrieve list of library resources libList, cacheId = getCache(libObj) if libList: inCache = True else: libList = libObj.scanResourcePath() inCache = False # go through list of library resources and add suitable for resource in libList: # scanResourcePath() yields absolute paths to a resource, but # we only want to match against the 'resource' part of it resourcePart = Path.getCommonPrefix(libObj._resourcePath, resource)[2] if not inCache: cacheList.append(resource) if isSkipFile(resource): continue elif (filter and not filter(resourcePart)): continue else: yield resource if not inCache: # cache write self._genobj._cache.write(cacheId, cacheList, memory=True, writeToFile=False) return
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] = 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.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()