Dear all,

This is a continuation of the discussion on "Link to Chinese translation in Wiki frontpage" dated 7 May 2009.

To re-cap, I have suggested that the patch in http://moinmo.in/FeatureRequests/ThisPageInOtherLanguages can be used to automatically generate links to translated pages at bottom right of the wiki panel. In addition, I have proposed that the use of a dictionary to look for translated page names should be dropped from the patch, since our wiki strictly uses locale prefixes to label translated pages.

To that end, I have cooked up the proposed patch targeted for MoinMoin 1.5.9 (available in CentOS 5.5). I have uploaded the patch to http://moinmo.in/FeatureRequests/ThisPageInOtherLanguages?action=AttachFile&do=view&target=simpler.patch . It is also attached here.

I sincerely hope that the patch can be applied to the official CentOS wiki, thereby making all translated pages a lot more more accessible to the public.

Regards,
Timothy Lee

--- MoinMoin/web/static/htdocs/modern/css/screen.css.orig	2006-11-21 03:51:13.000000000 +0800
+++ MoinMoin/web/static/htdocs/modern/css/screen.css	2010-10-13 12:06:21.000000000 +0800
@@ -246,6 +246,41 @@
     background: #81BBF2; /* url(../img/tab-selected.png) repeat-x; */
 }
 
+#langbar {
+    display: block;
+    margin: 0;
+    padding: 0 10px;
+    font-size: 0.82em;
+    zoom: 1; /* for avoiding a gap between langbar and pageline on IE */
+}
+
+#langbar li {
+    float: right;
+    display: inline;
+    margin: 0 2px;
+    padding: 2px 5px;
+    border: 1px solid #9C9C9C;
+    border-bottom: none;
+    white-space: nowrap;
+}
+
+*[dir="rtl"] #langbar li {
+    float: left;
+}
+
+#langbar li.wikilink {
+    background: white; /*url(../img/tab-wiki.png) repeat-x;*/
+}
+
+#langbar a, #langbar a:visited {
+    color: black;
+    text-decoration: none;    
+}
+
+#langbar li:hover {
+    background: #CCCCCC;
+}
+
 #pageline {
     clear: both;
     margin: 0;
--- MoinMoin/theme/modern.py.orig	2006-05-12 00:24:00.000000000 +0800
+++ MoinMoin/theme/modern.py	2010-10-13 13:14:24.000000000 +0800
@@ -34,6 +34,7 @@
             u'</div>',
             self.trail(d),
             self.navibar(d),
+            self.langbar(d),
             #u'<hr id="pageline">',
             u'<div id="pageline"><hr style="display:none;"></div>',
             self.msg(d),
@@ -48,6 +49,49 @@
         ]
         return u'\n'.join(html)
 
+    def langbar(self, d):
+        """ Create language panel
+
+        @param d: parameter dictionary
+        @rtype: unicode
+        @return: language panel html
+        """
+        from MoinMoin.util import pysupport
+        from MoinMoin.Page import Page
+        from MoinMoin import i18n
+
+        # Find page without i18n prefix (assumed to be in English)
+        org = d['page_name']
+        p = org.split('/')
+        if len(p) > 1 and p[0] in i18n.languages:
+            del p[0]
+        bare = u'/'.join(p)
+
+        # Setup a list of pages to check for
+        names = {bare: 'English'}
+        for lang in i18n.wikiLanguages():
+            lang_module = 'MoinMoin.i18n.%s' % i18n.filename(lang)
+            meta = pysupport.importName(lang_module, "meta") 
+            names[lang + '/' + bare] = meta['language'].decode('utf-8')
+        del names[org]
+
+        # Check for other translations now
+        item = u'<li class="wikilink">%s</li>'
+        items = []
+        for n in names:
+            translation = Page(self.request, n)
+            if translation.exists():
+                link = translation.link_to(self.request, names[n])
+                items.append(item % link)
+
+        if items:
+            # Assemble html
+            items = u''.join(items)
+            html = u'<ul id="langbar">%s</ul>' % items
+            return html
+        else:
+            return u''
+
     def editorheader(self, d, **kw):
         """ Assemble wiki header for editor
         
_______________________________________________
CentOS-docs mailing list
CentOS-docs@centos.org
http://lists.centos.org/mailman/listinfo/centos-docs

Reply via email to