= CheckTranslation based on wiki pos = It would help translators if the `CheckTranslation` action in master wiki was based on the wiki pos, not `MoinMoin/i18n`. Currently, when we update page titles in the po page, `CheckTranslation` becomes outdated until the changes are merged with the code base. == Patch == ThomasWaldmann said i18n needs a rewrite anyway, so one could create a storage backend for it, targeted at Moin 2. However I was thinking about something simpler for improving translation process right now. We could allow `MoinMoin.i18n.Translation` to load the language from a given page rather than a file, then `CheckTranslation`, running on the master wiki, would pass the po pages for setting up a custom translation subsystem. Here is a 1.9.0 patch for implementing this: {{{#!highlight diff --- MoinMoin/i18n/__init__.py 2010-01-16 16:06:48 +0000 +++ MoinMoin/i18n/__init__.py 2010-01-16 23:31:23 +0000 @@ -152,11 +152,15 @@ self.language = language self.domain = domain - def load_po(self, f): + def load_po(self, source): """ load the po file """ from MoinMoin.i18n.msgfmt import MsgFmt mf = MsgFmt() - mf.read_po(f.readlines()) + from MoinMoin.Page import Page + if isinstance(source, Page): + mf.read_po(source.getlines()) + else: + mf.read_po(source.readlines()) mo_data = mf.generate_mo() f = StringIO(mo_data) self.load_mo(f) @@ -219,11 +223,14 @@ text = text.strip() return text - def loadLanguage(self, request, trans_dir="i18n"): + def loadLanguage(self, request, trans_dir="i18n", source_page=None): request.clock.start('loadLanguage') # see comment about per-wiki scope above cache = caching.CacheEntry(request, arena='i18n', key=self.language, scope='wiki', use_pickle=True) - langfilename = po_filename(request, self.language, self.domain, i18n_dir=trans_dir) + if source_page is None: + langfilename = po_filename(request, self.language, self.domain, i18n_dir=trans_dir) + else: + langfilename = source_page.getPagePath() needsupdate = cache.needsUpdate(langfilename) if not needsupdate: try: @@ -232,12 +239,14 @@ except caching.CacheError: logging.debug("pickle %s load failed" % self.language) needsupdate = 1 - if needsupdate: - logging.debug("langfilename %s needs update" % langfilename) - f = file(langfilename) - self.load_po(f) - f.close() + if source_page is None: + logging.debug("langfilename %s needs update" % langfilename) + f = file(langfilename) + self.load_po(f) + f.close() + else: + self.load_po(source_page) trans = self.translation unformatted = trans._catalog self.has_wikimarkup = self.info.get('x-haswikimarkup', 'False') == 'True' --- CheckTranslation.py 2010-01-16 17:16:06 +0000 +++ CheckTranslation.py 2010-01-16 22:10:50 +0000 @@ -13,7 +13,7 @@ import re, time from MoinMoin import i18n, search -from MoinMoin.i18n import strings +from MoinMoin.i18n import strings, Translation i18n.strings = strings from MoinMoin.Page import Page @@ -44,6 +44,8 @@ '%Y-%m-%d', ] +i18n_page = u"MoinI18n" + def execute(pagename, request): _ = request.getText @@ -53,7 +55,7 @@ pageset = getattr(i18n.strings, pageset_name) not_translated_system_pages_set = getattr(i18n.strings, "not_translated_system_pages") - if pagename.startswith(u"MoinI18n/"): + if pagename.startswith(u"%s/" % i18n_page): # if we get called from one of the pages on MoinMaster that contain # the .po file data, we assume that user wants to check THAT language: lang_default = pagename[9:] @@ -67,8 +69,28 @@ request.theme.add_msg(msg, "err") lang = 'en' + def master_translations(request=request): + """Load translations from the master wiki.""" + translations = {} + for language in wiki_languages: + # A dummy language is needed otherwise translation cache will be overwritten + # For a proposed solution see http://moinmo.in/MoinMoinPatch/AddTranslationDomainToCacheKey + dummy_language = 'CheckTranslation_%s' % language + t = Translation(dummy_language) + wiki_po = page = Page(request, u"%s/%s" % (i18n_page, language)) + t.loadLanguage(request, source_page=wiki_po) + translations[language] = {} + for key, text in t.raw.items(): + translations[language][key] = text + return translations + + translations = master_translations() + def trans(text, request=request, lang=lang, **kw): - return i18n.getText(text, request, lang, **kw) + try: + return translations[lang][text] + except KeyError: + return text data = TupleDataset() data.columns = [ }}} /* Requested by RenatoSilva */ /* Patched by RenatoSilva */ ---- CategoryFeatureRequest CategoryFeaturePatched