def getPoFile(self): '''Computes and returns the PO file corresponding to this translation.''' tool = self.tool fileName = os.path.join(getOsTempFolder(), '%s-%s.po' % (tool.o.getAppName(), self.id)) poFile = PoFile(fileName) for field in self.fields: if (field.name == 'title') or (field.type != 'String'): continue # Adds the PO message corresponding to this field msg = field.getValue(self.o) or '' for old, new in self.poReplacements: msg = msg.replace(old, new) poFile.addMessage(PoMessage(field.name, msg, '')) poFile.generate() return True, file(fileName)
def finalize(self): # Some useful aliases msg = PoMessage app = self.applicationName # Some global i18n messages poMsg = msg(app, '', app); poMsg.produceNiceDefault() self.labels += [poMsg, msg('workflow_state', '', msg.WORKFLOW_STATE), msg('appy_title', '', msg.APPY_TITLE), msg('data_change', '', msg.DATA_CHANGE), msg('modified_field', '', msg.MODIFIED_FIELD), msg('previous_value', '', msg.PREVIOUS_VALUE), msg('phase', '', msg.PHASE), msg('root_type', '', msg.ROOT_TYPE), msg('workflow_comment', '', msg.WORKFLOW_COMMENT), msg('choose_a_value', '', msg.CHOOSE_A_VALUE), msg('choose_a_doc', '', msg.CHOOSE_A_DOC), msg('min_ref_violated', '', msg.MIN_REF_VIOLATED), msg('max_ref_violated', '', msg.MAX_REF_VIOLATED), msg('no_ref', '', msg.REF_NO), msg('add_ref', '', msg.REF_ADD), msg('ref_actions', '', msg.REF_ACTIONS), msg('move_up', '', msg.REF_MOVE_UP), msg('move_down', '', msg.REF_MOVE_DOWN), msg('query_create', '', msg.QUERY_CREATE), msg('query_import', '', msg.QUERY_IMPORT), msg('query_no_result', '', msg.QUERY_NO_RESULT), msg('query_consult_all', '', msg.QUERY_CONSULT_ALL), msg('import_title', '', msg.IMPORT_TITLE), msg('import_show_hide', '', msg.IMPORT_SHOW_HIDE), msg('import_already', '', msg.IMPORT_ALREADY), msg('import_many', '', msg.IMPORT_MANY), msg('import_done', '', msg.IMPORT_DONE), msg('search_title', '', msg.SEARCH_TITLE), msg('search_button', '', msg.SEARCH_BUTTON), msg('search_objects', '', msg.SEARCH_OBJECTS), msg('search_results', '', msg.SEARCH_RESULTS), msg('search_results_descr', '', ' '), msg('search_new', '', msg.SEARCH_NEW), msg('search_from', '', msg.SEARCH_FROM), msg('search_to', '', msg.SEARCH_TO), msg('search_or', '', msg.SEARCH_OR), msg('search_and', '', msg.SEARCH_AND), msg('ref_invalid_index', '', msg.REF_INVALID_INDEX), msg('bad_long', '', msg.BAD_LONG), msg('bad_float', '', msg.BAD_FLOAT), msg('bad_email', '', msg.BAD_EMAIL), msg('bad_url', '', msg.BAD_URL), msg('bad_alphanumeric', '', msg.BAD_ALPHANUMERIC), msg('bad_select_value', '', msg.BAD_SELECT_VALUE), msg('select_delesect', '', msg.SELECT_DESELECT), msg('no_elem_selected', '', msg.NO_SELECTION), msg('delete_confirm', '', msg.DELETE_CONFIRM), msg('delete_done', '', msg.DELETE_DONE), msg('goto_first', '', msg.GOTO_FIRST), msg('goto_previous', '', msg.GOTO_PREVIOUS), msg('goto_next', '', msg.GOTO_NEXT), msg('goto_last', '', msg.GOTO_LAST), msg('goto_source', '', msg.GOTO_SOURCE), msg('whatever', '', msg.WHATEVER), msg('yes', '', msg.YES), msg('no', '', msg.NO), msg('field_required', '', msg.FIELD_REQUIRED), msg('field_invalid', '', msg.FIELD_INVALID), msg('file_required', '', msg.FILE_REQUIRED), msg('image_required', '', msg.IMAGE_REQUIRED), ] # Create a label for every role added by this application for role in self.getAllUsedRoles(): self.labels.append(msg('role_%s' % role.name,'', role.name, niceDefault=True)) # Create basic files (config.py, Install.py, etc) self.generateTool() self.generateInit() self.generateWorkflows() self.generateTests() if self.config.frontPage: self.generateFrontPage() self.copyFile('Install.py', self.repls, destFolder='Extensions') self.copyFile('configure.zcml', self.repls) self.copyFile('import_steps.xml', self.repls, destFolder='profiles/default') self.copyFile('ProfileInit.py', self.repls, destFolder='profiles', destName='__init__.py') self.copyFile('Portlet.pt', self.repls, destName='%s.pt' % self.portletName, destFolder=self.skinsFolder) self.copyFile('tool.gif', {}) self.copyFile('Styles.css.dtml',self.repls, destFolder=self.skinsFolder, destName = '%s.css.dtml' % self.applicationName) self.copyFile('IEFixes.css.dtml',self.repls,destFolder=self.skinsFolder) if self.config.minimalistPlone: self.copyFile('colophon.pt', self.repls,destFolder=self.skinsFolder) self.copyFile('footer.pt', self.repls, destFolder=self.skinsFolder) # Create version.txt f = open(os.path.join(self.outputFolder, 'version.txt'), 'w') f.write(self.version) f.close() # Make Extensions and tests Python packages for moduleFolder in ('Extensions', 'tests'): initFile = '%s/%s/__init__.py' % (self.outputFolder, moduleFolder) if not os.path.isfile(initFile): f = open(initFile, 'w') f.write('') f.close() # Decline i18n labels into versions for child classes for classDescr in self.classes: for poMsg in classDescr.labelsToPropagate: for childDescr in classDescr.getChildren(): childMsg = poMsg.clone(classDescr.name, childDescr.name) if childMsg not in self.labels: self.labels.append(childMsg) # Generate i18n pot file potFileName = '%s.pot' % self.applicationName if self.i18nFiles.has_key(potFileName): potFile = self.i18nFiles[potFileName] else: fullName = os.path.join(self.outputFolder, 'i18n/%s' % potFileName) potFile = PoFile(fullName) self.i18nFiles[potFileName] = potFile # We update the POT file with our list of automatically managed labels. removedLabels = potFile.update(self.labels, self.options.i18nClean, not self.options.i18nSort) if removedLabels: print 'Warning: %d messages were removed from translation ' \ 'files: %s' % (len(removedLabels), str(removedLabels)) # Before generating the POT file, we still need to add one label for # every page for the Translation class. We've not done it yet because # the number of pages depends on the total number of labels in the POT # file. pageLabels = [] nbOfPages = int(len(potFile.messages)/self.config.translationsPerPage)+1 for i in range(nbOfPages): msgId = '%s_page_%d' % (self.translation.name, i+2) pageLabels.append(msg(msgId, '', 'Page %d' % (i+2))) potFile.update(pageLabels, keepExistingOrder=False) potFile.generate() # Generate i18n po files for language in self.config.languages: # I must generate (or update) a po file for the language(s) # specified in the configuration. poFileName = potFile.getPoFileName(language) if self.i18nFiles.has_key(poFileName): poFile = self.i18nFiles[poFileName] else: fullName = os.path.join(self.outputFolder, 'i18n/%s' % poFileName) poFile = PoFile(fullName) self.i18nFiles[poFileName] = poFile poFile.update(potFile.messages, self.options.i18nClean, not self.options.i18nSort) poFile.generate() # Generate corresponding fields on the Translation class page = 'main' i = 0 for message in potFile.messages: i += 1 # A computed field is used for displaying the text to translate. self.translation.addLabelField(message.id, page) # A String field will hold the translation in itself. self.translation.addMessageField(message.id, page, self.i18nFiles) if (i % self.config.translationsPerPage) == 0: # A new page must be defined. if page == 'main': page = '2' else: page = str(int(page)+1) # Generate i18n po files for other potential files for poFile in self.i18nFiles.itervalues(): if not poFile.generated: poFile.generate() self.generateWrappers() self.generateConfig()