changeset 369:95269fc6bc51

CheckTranslation: some minor cleanups / fixes
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sun, 19 Apr 2009 13:01:52 +0200
parents f31618787bec
children 5dbd61612452
files data/plugin/action/CheckTranslation.py
diffstat 1 files changed, 42 insertions(+), 39 deletions(-) [+]
line wrap: on
line diff
--- a/data/plugin/action/CheckTranslation.py	Sun Apr 19 10:19:02 2009 +0200
+++ b/data/plugin/action/CheckTranslation.py	Sun Apr 19 13:01:52 2009 +0200
@@ -5,45 +5,47 @@
     shows a table of System Pages and their translations to the users language
     if the users language is anything else than en
 
-    @copyright: 2009 MoinMoin:ReimarBauer
+    @copyright: 2009 MoinMoin:ReimarBauer,
+                2009 MoinMoin:ThomasWaldmann
     @license: GNU GPL, see COPYING for details.
 """
 
+from MoinMoin import i18n
 from MoinMoin.i18n import strings
+i18n.strings = strings
+
 from MoinMoin.Page import Page
 from MoinMoin.util.dataset import TupleDataset, Column
 from MoinMoin.widget.browser import DataBrowserWidget
 
-def lang_select():
-    """ Create language selection. """
-    from MoinMoin import i18n
-    return i18n.wikiLanguages().keys()
             
 def execute(pagename, request):
     _ = request.getText
-
-    selection = request.values.get('selection') or u'all_pages'
+    wiki_languages = i18n.wikiLanguages().keys()
 
-    # ToDo find a better way to use only list definitions
-    if selection.startswith('__') or not selection in dir(strings):
-        selection = u'all_pages'
+    pageset_name = request.values.get('pageset')
+    try:
+        pageset = getattr(i18n.strings, pageset_name)
+        assert isinstance(pageset, (list, tuple))
+    except (AttributeError, TypeError, AssertionError):
+        pageset_name = 'all_pages'
+        pageset = getattr(i18n.strings, pageset_name)
 
-    SystemPages = getattr(strings, selection)
-
-    users_lang = request.values.get('language') or (request.user.valid and request.user.language) or 'en'
-    if users_lang == "en" or users_lang not in lang_select():
-        msg = _("Please select an other language than english in your settings for this action (%s)" % ' '.join(lang_select()))
+    lang = request.values.get('language') or (request.user.valid and request.user.language) or 'en'
+    if lang == "en" or lang not in wiki_languages:
+        msg = _("Please select another language than '%s' for this action (%s)") % (
+              lang, ' '.join(wiki_languages))
         request.theme.add_msg(msg, "err")
         Page(request, pagename).send_page()
         return
 
-    request.lang = users_lang
-    _ = request.getText # translation mapping needs to be refreshed
+    def trans(text, request=request, lang=lang, **kw):
+        return i18n.getText(text, request, lang, **kw)
 
     data = TupleDataset()
     data.columns = [
-           Column('en', label=_('Developer language')),
-           Column(users_lang, label=_('Preferred language')),
+           Column('en', label=_('Original page')),
+           Column(lang, label=_('Translated page')),
            Column('status', label=_('Status')),
         ]
 
@@ -51,34 +53,35 @@
     edit_attrs = {'name': 'editlink', 'rel': 'nofollow', }
     raw_querystr = {'action': 'raw'}
 
-    for page_name in SystemPages:
-        master = Page(request, page_name)
-        translated = Page(request, _(page_name))
-        master_last_edit_info = master.lastEditInfo()
-        translated_last_edit_info = translated.lastEditInfo()
+    for orig_page_name in pageset:
+        trans_page_name = trans(orig_page_name)
+        orig_page = Page(request, orig_page_name)
+        trans_page = Page(request, trans_page_name)
 
         status = []
-        status.append("size: %s, %s" % (master.size(), translated.size()))
-        if master_last_edit_info != {}:
-            status.append('<hr>')
-            status.append("last master editor: %(editor)s" % master_last_edit_info)
-            status.append("last master edit time: %(time)s" % master_last_edit_info)
+        status.append("size: %s, %s" % (orig_page.size(), trans_page.size()))
 
-        if translated_last_edit_info != {}:
+        orig_last_edit_info = orig_page.lastEditInfo()
+        if orig_last_edit_info:
             status.append('<hr>')
-            status.append("last translation editor: %(editor)s" % translated_last_edit_info)
-            status.append("last translation edit time: %(time)s" % translated_last_edit_info)
+            status.append("last original page editor: %(editor)s" % orig_last_edit_info)
+            status.append("last original page edit time: %(time)s" % orig_last_edit_info)
 
-        status = '<br>'.join(status)
-        status = "%s</br>" % status
-        data.addRow((master.link_to(request, page_name, querystr=raw_querystr),
-                                    translated.link_to(request, _(page_name), querystr=edit_querystr, **edit_attrs), status))
+        trans_last_edit_info = trans_page.lastEditInfo()
+        if trans_last_edit_info:
+            status.append('<hr>')
+            status.append("last translation editor: %(editor)s" % trans_last_edit_info)
+            status.append("last translation edit time: %(time)s" % trans_last_edit_info)
+
+        data.addRow((orig_page.link_to(request, orig_page_name, querystr=raw_querystr),
+                     trans_page.link_to(request, trans_page_name, querystr=edit_querystr, **edit_attrs),
+                     '<br>'.join(status)))
 
     table = DataBrowserWidget(request)
     table.setData(data)
 
     msg = ''.join(table.format(method='GET'))
-    msg = 'Help pages and their translations to "%s" of selection: "%s" %s' % (users_lang, selection, msg)
-    if msg:
-        request.theme.add_msg(msg, "info")
+    msg = "Pages and their translations to '%s' of pageset '%s' %s" % (lang, pageset_name, msg)
+    request.theme.add_msg(msg, "info")
     Page(request, pagename).send_page()
+