Other languages links
I moderatly use the MultiLang features of MoinMoin. One of the things that are dearly missing is a GUI for telling us which pages are translations of the current page, yes, the way MediaWiki does (them again!).
I think there could be a way to fixup a theme to do just that, i'll think of something. -- TheAnarcat 2006-01-21 21:32:16
I have successfully modified a rightsidebar-based theme to add an "other languages" box. The way the box works is that it relies on the i18n engine (which includes LangDict pages) to find if there's a translation of the current page. It iterates over all known dictionnaries and tries to find the current page in there. For every match, it will list a link to the related page with the language name as the text of the link.
Apply the patch provided below (it simply patches the theme). To link pages together, you need to edit the LangDicts. So for example, if you want to link FrontPage to StartSeite, you'll want to edit the GermandDict to have an entry like:
This is the code that generates the panel in the theme.
1 def langpanel(self, d): 2 """ Create language panel """ 3 from MoinMoin import i18n 4 from MoinMoin.i18n import _unformatted_text_cache 5 from types import * 6 _ = self.request.getText 7 8 page_title = d['page_name'] 9 lang_links =  10 request = self.request 11 for l in i18n.languages: 12 trans = i18n.getText(page_title, self.request, l, False) 13 if trans == page_title: 14 lang = Page(self.request, page_title).language 15 if lang is None: 16 # this is a hack: the page should always have a lang, and the default should not be .fr 17 lang = 'fr' 18 ## costly hideous operation to find the root page name in english 19 global _unformatted_text_cache 20 if not lang in _unformatted_text_cache: 21 (texts, unformatted) = i18n.loadLanguage(request, lang) 22 # XXX add error handling 23 _unformatted_text_cache[lang] = unformatted 24 for k, v in _unformatted_text_cache[lang].iteritems(): 25 if v == page_title: 26 trans = i18n.getText(k, self.request, l, False) 27 en = i18n.getText(k, self.request, 'en', False) 28 if trans == en and l != 'en': 29 trans = page_title # false translation 30 else: 31 en = i18n.getText(page_title, self.request, 'en', False) 32 if trans == en and l != 'en': 33 trans = page_title # false translation 34 35 if trans != page_title: 36 translated_page = Page(self.request, trans) 37 if translated_page.exists(): 38 lang_links.append(translated_page.link_to(request, l)) 39 40 if lang_links: 41 html = [ 42 u'<div class="sidepanel">', 43 u'<h1>%s</h1>' % _("Other languages"), 44 u'\n'.join(lang_links), 45 u'</div>' 46 ] 47 return u'\n'.join(html) 48 else: 49 return u''
langpanel must obviously be called somewhere in the theme for this to work, generally in the header function:
--- alex.py.orig Sat Jan 21 18:09:37 2006 +++ alex.py Sat Jan 21 18:09:39 2006 @@ -107,6 +107,7 @@ self.wikipanel(d), self.pagepanel(d), self.userpanel(d), + self.langpanel(d), self.credits(d), u'</div>',
I have updated the above code to use the builtin translation system instead of looking manually through the dicts so that we benefit from the builtin translations for (e.g.) the system pages. -- TheAnarcat 2007-04-11 04:48:21
There is a simpler patch below which dispenses with translated page name and just searches for pages with a locale prefix. For example, FrontPage will look for translations in br/FrontPage, fr/FrontPage, zh/FrontPage, etc. Translated pages will link back to the default version plus other translations, ie: fr/FrontPage will offer a link to FrontPage in addition to other translated pages. -- 2010-10-13 13:30:00
Updates: simpler.patch looks only for pages with locale prefix. -- 2010-10-13 13:30:00
I don't think this method scales to the level we need (interconnecting a wiki farm of a dozend wikis with some thousand pages each and more).
How could I create a "translate this page button"? I guess it would have to lead to a form like this:
<form method="GET"> <input name="rootpage" type="hidden" value="%current-page%" /> <input name="newpage" type="textfield" value="%current-page%" /> <input type="submit" /> </form>
I think I can figure out how to do that, but the issue for me is to redirect this to another page that will then, itself, redirect to the new page (to create it) with ?action=edit&template=%current-page% appended... Any ideas? -- TheAnarcat 2007-03-23 19:38:35
I think this is a nice feature. I would like to suggest to add this to the header of a page:
<link title="FrontPage in german" rel="alternate" hreflang="de" href="StartSeite">