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:
1 --- MoinMoin/i18n/__init__.py 2010-01-16 16:06:48 +0000
2 +++ MoinMoin/i18n/__init__.py 2010-01-16 23:31:23 +0000
3 @@ -152,11 +152,15 @@
4 self.language = language
5 self.domain = domain
6
7 - def load_po(self, f):
8 + def load_po(self, source):
9 """ load the po file """
10 from MoinMoin.i18n.msgfmt import MsgFmt
11 mf = MsgFmt()
12 - mf.read_po(f.readlines())
13 + from MoinMoin.Page import Page
14 + if isinstance(source, Page):
15 + mf.read_po(source.getlines())
16 + else:
17 + mf.read_po(source.readlines())
18 mo_data = mf.generate_mo()
19 f = StringIO(mo_data)
20 self.load_mo(f)
21 @@ -219,11 +223,14 @@
22 text = text.strip()
23 return text
24
25 - def loadLanguage(self, request, trans_dir="i18n"):
26 + def loadLanguage(self, request, trans_dir="i18n", source_page=None):
27 request.clock.start('loadLanguage')
28 # see comment about per-wiki scope above
29 cache = caching.CacheEntry(request, arena='i18n', key=self.language, scope='wiki', use_pickle=True)
30 - langfilename = po_filename(request, self.language, self.domain, i18n_dir=trans_dir)
31 + if source_page is None:
32 + langfilename = po_filename(request, self.language, self.domain, i18n_dir=trans_dir)
33 + else:
34 + langfilename = source_page.getPagePath()
35 needsupdate = cache.needsUpdate(langfilename)
36 if not needsupdate:
37 try:
38 @@ -232,12 +239,14 @@
39 except caching.CacheError:
40 logging.debug("pickle %s load failed" % self.language)
41 needsupdate = 1
42 -
43 if needsupdate:
44 - logging.debug("langfilename %s needs update" % langfilename)
45 - f = file(langfilename)
46 - self.load_po(f)
47 - f.close()
48 + if source_page is None:
49 + logging.debug("langfilename %s needs update" % langfilename)
50 + f = file(langfilename)
51 + self.load_po(f)
52 + f.close()
53 + else:
54 + self.load_po(source_page)
55 trans = self.translation
56 unformatted = trans._catalog
57 self.has_wikimarkup = self.info.get('x-haswikimarkup', 'False') == 'True'
58
59 --- CheckTranslation.py 2010-01-16 17:16:06 +0000
60 +++ CheckTranslation.py 2010-01-16 22:10:50 +0000
61 @@ -13,7 +13,7 @@
62
63 import re, time
64 from MoinMoin import i18n, search
65 -from MoinMoin.i18n import strings
66 +from MoinMoin.i18n import strings, Translation
67 i18n.strings = strings
68
69 from MoinMoin.Page import Page
70 @@ -44,6 +44,8 @@
71 '%Y-%m-%d',
72 ]
73
74 +i18n_page = u"MoinI18n"
75 +
76 def execute(pagename, request):
77 _ = request.getText
78
79 @@ -53,7 +55,7 @@
80 pageset = getattr(i18n.strings, pageset_name)
81 not_translated_system_pages_set = getattr(i18n.strings, "not_translated_system_pages")
82
83 - if pagename.startswith(u"MoinI18n/"):
84 + if pagename.startswith(u"%s/" % i18n_page):
85 # if we get called from one of the pages on MoinMaster that contain
86 # the .po file data, we assume that user wants to check THAT language:
87 lang_default = pagename[9:]
88 @@ -67,8 +69,28 @@
89 request.theme.add_msg(msg, "err")
90 lang = 'en'
91
92 + def master_translations(request=request):
93 + """Load translations from the master wiki."""
94 + translations = {}
95 + for language in wiki_languages:
96 + # A dummy language is needed otherwise translation cache will be overwritten
97 + # For a proposed solution see http://moinmo.in/MoinMoinPatch/AddTranslationDomainToCacheKey
98 + dummy_language = 'CheckTranslation_%s' % language
99 + t = Translation(dummy_language)
100 + wiki_po = page = Page(request, u"%s/%s" % (i18n_page, language))
101 + t.loadLanguage(request, source_page=wiki_po)
102 + translations[language] = {}
103 + for key, text in t.raw.items():
104 + translations[language][key] = text
105 + return translations
106 +
107 + translations = master_translations()
108 +
109 def trans(text, request=request, lang=lang, **kw):
110 - return i18n.getText(text, request, lang, **kw)
111 + try:
112 + return translations[lang][text]
113 + except KeyError:
114 + return text
115
116 data = TupleDataset()
117 data.columns = [