view data/plugin/action/ @ 374:e93b8be38fcc

CheckTranslation: more compact rendering
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sun, 19 Apr 2009 15:18:20 +0200
parents 0edec6b35559
children 005e0551b2c6
line wrap: on
line source
# -*- coding: iso-8859-1 -*-
    MoinMoin -

    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,
                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 execute(pagename, request):
    _ = request.getText

    pageset_name = request.values.get('pageset')
    if pageset_name not in i18n.strings.pagesets:
        pageset_name = 'all_pages'
    pageset = getattr(i18n.strings, pageset_name)

    lang = request.values.get('language') or request.lang or 'en'
    wiki_languages = sorted(i18n.wikiLanguages().keys())
    if lang not in wiki_languages:
        msg = _("We have no translation for '%s', falling back to 'en'!") % lang
        request.theme.add_msg(msg, "err")
        lang = 'en'

    def trans(text, request=request, lang=lang, **kw):
        return i18n.getText(text, request, lang, **kw)

    data = TupleDataset()
    data.columns = [
           Column('en', label=_('Original page')),
           Column(lang, label=_('Translated page')),
           Column('status', label=_('Status')),

    edit_querystr = {'action': 'edit', 'editor': 'text'}
    edit_attrs = {'name': 'editlink', 'rel': 'nofollow', }
    raw_querystr = {'action': 'raw'}

    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)

        orig_status = ["Original:"]
        orig_status.append("size: %s" % orig_page.size())
        last_edit = orig_page.lastEditInfo()
        orig_status.append(last_edit and "last edit: %(editor)s %(time)s" % last_edit or "")

        trans_status = ["Translation:"]
        trans_status.append("size: %s, %s" % trans_page.size())
        last_edit = trans_page.lastEditInfo()
        trans_status.append(last_edit and "last edit: %(editor)s %(time)s" % last_edit or "")

        status = orig_status + ["<hr>"] + trans_status
        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),

    table = DataBrowserWidget(request)
    page_table = ''.join(table.format(method='GET'))
    fmt = request.formatter
    this_page = Page(request, pagename)
    lang_links = [this_page.link_to_raw(request, _lang,
                                        querystr={'action': 'CheckTranslation',
                                                  'language': _lang,
                                                  'pageset': pageset_name, })
                  for _lang in wiki_languages if _lang != "en"]

    lang_selector = u''.join([fmt.paragraph(1), _("Choose:"), ' ', ' '.join(lang_links), fmt.paragraph(0)])

    pageset_links = [this_page.link_to_raw(request, _pageset_name,
                                           querystr={'action': 'CheckTranslation',
                                                     'language': lang,
                                                     'pageset': _pageset_name, })
                     for _pageset_name in sorted(i18n.strings.pagesets)]

    pageset_selector = u''.join([fmt.paragraph(1), _("Choose:"), ' ', ' '.join(pageset_links), fmt.paragraph(0)])

    title = _("Checking translation '%s' for page set '%s'") % (lang, pageset_name)
    request.theme.send_title(title,, pagename=pagename)