annotate data/plugin/action/CheckTranslation.py @ 375:005e0551b2c6

CheckTranslation: fixes and better rendering
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sun, 19 Apr 2009 15:23:44 +0200
parents e93b8be38fcc
children 2425d9e491dc
rev   line source
363
2bf44dde5191 shows a table of System Pages and their translations to the users language
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
1 # -*- coding: iso-8859-1 -*-
2bf44dde5191 shows a table of System Pages and their translations to the users language
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
2 """
364
5fbb949f75d2 action SystemPages renamed to CheckTranslation
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 363
diff changeset
3 MoinMoin - CheckTranslation.py
363
2bf44dde5191 shows a table of System Pages and their translations to the users language
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
4
2bf44dde5191 shows a table of System Pages and their translations to the users language
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
5 shows a table of System Pages and their translations to the users language
368
f31618787bec action.CheckTranslation: optional parameter language added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 367
diff changeset
6 if the users language is anything else than en
363
2bf44dde5191 shows a table of System Pages and their translations to the users language
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
7
369
95269fc6bc51 CheckTranslation: some minor cleanups / fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 368
diff changeset
8 @copyright: 2009 MoinMoin:ReimarBauer,
95269fc6bc51 CheckTranslation: some minor cleanups / fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 368
diff changeset
9 2009 MoinMoin:ThomasWaldmann
363
2bf44dde5191 shows a table of System Pages and their translations to the users language
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
10 @license: GNU GPL, see COPYING for details.
2bf44dde5191 shows a table of System Pages and their translations to the users language
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
11 """
2bf44dde5191 shows a table of System Pages and their translations to the users language
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
12
369
95269fc6bc51 CheckTranslation: some minor cleanups / fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 368
diff changeset
13 from MoinMoin import i18n
363
2bf44dde5191 shows a table of System Pages and their translations to the users language
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
14 from MoinMoin.i18n import strings
369
95269fc6bc51 CheckTranslation: some minor cleanups / fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 368
diff changeset
15 i18n.strings = strings
95269fc6bc51 CheckTranslation: some minor cleanups / fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 368
diff changeset
16
363
2bf44dde5191 shows a table of System Pages and their translations to the users language
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
17 from MoinMoin.Page import Page
2bf44dde5191 shows a table of System Pages and their translations to the users language
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
18 from MoinMoin.util.dataset import TupleDataset, Column
2bf44dde5191 shows a table of System Pages and their translations to the users language
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
19 from MoinMoin.widget.browser import DataBrowserWidget
2bf44dde5191 shows a table of System Pages and their translations to the users language
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
20
368
f31618787bec action.CheckTranslation: optional parameter language added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 367
diff changeset
21
363
2bf44dde5191 shows a table of System Pages and their translations to the users language
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
22 def execute(pagename, request):
2bf44dde5191 shows a table of System Pages and their translations to the users language
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
23 _ = request.getText
366
c53c862bd556 action.CeckTranslations: added an optional parameter selection to get another pageslist shown than all_pages (see i18n.strings for list definitions).
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 365
diff changeset
24
369
95269fc6bc51 CheckTranslation: some minor cleanups / fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 368
diff changeset
25 pageset_name = request.values.get('pageset')
372
4c9654b4f335 CheckTranslation: add pageset selector
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 371
diff changeset
26 if pageset_name not in i18n.strings.pagesets:
369
95269fc6bc51 CheckTranslation: some minor cleanups / fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 368
diff changeset
27 pageset_name = 'all_pages'
372
4c9654b4f335 CheckTranslation: add pageset selector
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 371
diff changeset
28 pageset = getattr(i18n.strings, pageset_name)
366
c53c862bd556 action.CeckTranslations: added an optional parameter selection to get another pageslist shown than all_pages (see i18n.strings for list definitions).
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 365
diff changeset
29
370
5dbd61612452 CheckTranslation: transforming it into a real action
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 369
diff changeset
30 lang = request.values.get('language') or request.lang or 'en'
371
36a99c8244dc CheckTranslation: adding language selector
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 370
diff changeset
31 wiki_languages = sorted(i18n.wikiLanguages().keys())
373
0edec6b35559 CheckTranslation: if lang selection is invalid, give notice and fall back to 'en'
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 372
diff changeset
32 if lang not in wiki_languages:
0edec6b35559 CheckTranslation: if lang selection is invalid, give notice and fall back to 'en'
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 372
diff changeset
33 msg = _("We have no translation for '%s', falling back to 'en'!") % lang
363
2bf44dde5191 shows a table of System Pages and their translations to the users language
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
34 request.theme.add_msg(msg, "err")
373
0edec6b35559 CheckTranslation: if lang selection is invalid, give notice and fall back to 'en'
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 372
diff changeset
35 lang = 'en'
363
2bf44dde5191 shows a table of System Pages and their translations to the users language
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
36
369
95269fc6bc51 CheckTranslation: some minor cleanups / fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 368
diff changeset
37 def trans(text, request=request, lang=lang, **kw):
95269fc6bc51 CheckTranslation: some minor cleanups / fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 368
diff changeset
38 return i18n.getText(text, request, lang, **kw)
368
f31618787bec action.CheckTranslation: optional parameter language added
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 367
diff changeset
39
363
2bf44dde5191 shows a table of System Pages and their translations to the users language
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
40 data = TupleDataset()
2bf44dde5191 shows a table of System Pages and their translations to the users language
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
41 data.columns = [
369
95269fc6bc51 CheckTranslation: some minor cleanups / fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 368
diff changeset
42 Column('en', label=_('Original page')),
95269fc6bc51 CheckTranslation: some minor cleanups / fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 368
diff changeset
43 Column(lang, label=_('Translated page')),
365
951d12e53825 action.CheckTranslation: changed links for master to raw page and for the translated page to edit link. Another column of status data added (size and last editor).
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 364
diff changeset
44 Column('status', label=_('Status')),
363
2bf44dde5191 shows a table of System Pages and their translations to the users language
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
45 ]
2bf44dde5191 shows a table of System Pages and their translations to the users language
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
46
365
951d12e53825 action.CheckTranslation: changed links for master to raw page and for the translated page to edit link. Another column of status data added (size and last editor).
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 364
diff changeset
47 edit_querystr = {'action': 'edit', 'editor': 'text'}
951d12e53825 action.CheckTranslation: changed links for master to raw page and for the translated page to edit link. Another column of status data added (size and last editor).
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 364
diff changeset
48 edit_attrs = {'name': 'editlink', 'rel': 'nofollow', }
951d12e53825 action.CheckTranslation: changed links for master to raw page and for the translated page to edit link. Another column of status data added (size and last editor).
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 364
diff changeset
49 raw_querystr = {'action': 'raw'}
951d12e53825 action.CheckTranslation: changed links for master to raw page and for the translated page to edit link. Another column of status data added (size and last editor).
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 364
diff changeset
50
369
95269fc6bc51 CheckTranslation: some minor cleanups / fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 368
diff changeset
51 for orig_page_name in pageset:
95269fc6bc51 CheckTranslation: some minor cleanups / fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 368
diff changeset
52 trans_page_name = trans(orig_page_name)
95269fc6bc51 CheckTranslation: some minor cleanups / fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 368
diff changeset
53 orig_page = Page(request, orig_page_name)
95269fc6bc51 CheckTranslation: some minor cleanups / fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 368
diff changeset
54 trans_page = Page(request, trans_page_name)
365
951d12e53825 action.CheckTranslation: changed links for master to raw page and for the translated page to edit link. Another column of status data added (size and last editor).
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 364
diff changeset
55
374
e93b8be38fcc CheckTranslation: more compact rendering
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 373
diff changeset
56 orig_status = ["Original:"]
375
005e0551b2c6 CheckTranslation: fixes and better rendering
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 374
diff changeset
57 orig_status.append("size: %d" % orig_page.size())
374
e93b8be38fcc CheckTranslation: more compact rendering
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 373
diff changeset
58 last_edit = orig_page.lastEditInfo()
375
005e0551b2c6 CheckTranslation: fixes and better rendering
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 374
diff changeset
59 if last_edit:
005e0551b2c6 CheckTranslation: fixes and better rendering
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 374
diff changeset
60 orig_status.append("last edit: %(editor)s %(time)s" % last_edit)
365
951d12e53825 action.CheckTranslation: changed links for master to raw page and for the translated page to edit link. Another column of status data added (size and last editor).
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 364
diff changeset
61
374
e93b8be38fcc CheckTranslation: more compact rendering
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 373
diff changeset
62 trans_status = ["Translation:"]
375
005e0551b2c6 CheckTranslation: fixes and better rendering
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 374
diff changeset
63 trans_status.append("size: %d" % trans_page.size())
374
e93b8be38fcc CheckTranslation: more compact rendering
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 373
diff changeset
64 last_edit = trans_page.lastEditInfo()
375
005e0551b2c6 CheckTranslation: fixes and better rendering
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 374
diff changeset
65 if last_edit:
005e0551b2c6 CheckTranslation: fixes and better rendering
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 374
diff changeset
66 trans_status.append("last edit: %(editor)s %(time)s" % last_edit)
365
951d12e53825 action.CheckTranslation: changed links for master to raw page and for the translated page to edit link. Another column of status data added (size and last editor).
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 364
diff changeset
67
375
005e0551b2c6 CheckTranslation: fixes and better rendering
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 374
diff changeset
68 status = "<br>".join(orig_status) + "<hr>" + "<br>".join(trans_status)
369
95269fc6bc51 CheckTranslation: some minor cleanups / fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 368
diff changeset
69 data.addRow((orig_page.link_to(request, orig_page_name, querystr=raw_querystr),
95269fc6bc51 CheckTranslation: some minor cleanups / fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 368
diff changeset
70 trans_page.link_to(request, trans_page_name, querystr=edit_querystr, **edit_attrs),
375
005e0551b2c6 CheckTranslation: fixes and better rendering
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 374
diff changeset
71 status))
363
2bf44dde5191 shows a table of System Pages and their translations to the users language
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
72
2bf44dde5191 shows a table of System Pages and their translations to the users language
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
73 table = DataBrowserWidget(request)
2bf44dde5191 shows a table of System Pages and their translations to the users language
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
74 table.setData(data)
371
36a99c8244dc CheckTranslation: adding language selector
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 370
diff changeset
75 page_table = ''.join(table.format(method='GET'))
36a99c8244dc CheckTranslation: adding language selector
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 370
diff changeset
76
36a99c8244dc CheckTranslation: adding language selector
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 370
diff changeset
77 fmt = request.formatter
36a99c8244dc CheckTranslation: adding language selector
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 370
diff changeset
78 this_page = Page(request, pagename)
36a99c8244dc CheckTranslation: adding language selector
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 370
diff changeset
79 lang_links = [this_page.link_to_raw(request, _lang,
36a99c8244dc CheckTranslation: adding language selector
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 370
diff changeset
80 querystr={'action': 'CheckTranslation',
36a99c8244dc CheckTranslation: adding language selector
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 370
diff changeset
81 'language': _lang,
36a99c8244dc CheckTranslation: adding language selector
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 370
diff changeset
82 'pageset': pageset_name, })
36a99c8244dc CheckTranslation: adding language selector
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 370
diff changeset
83 for _lang in wiki_languages if _lang != "en"]
36a99c8244dc CheckTranslation: adding language selector
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 370
diff changeset
84
36a99c8244dc CheckTranslation: adding language selector
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 370
diff changeset
85
36a99c8244dc CheckTranslation: adding language selector
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 370
diff changeset
86 lang_selector = u''.join([fmt.paragraph(1), _("Choose:"), ' ', ' '.join(lang_links), fmt.paragraph(0)])
363
2bf44dde5191 shows a table of System Pages and their translations to the users language
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
87
372
4c9654b4f335 CheckTranslation: add pageset selector
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 371
diff changeset
88 pageset_links = [this_page.link_to_raw(request, _pageset_name,
4c9654b4f335 CheckTranslation: add pageset selector
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 371
diff changeset
89 querystr={'action': 'CheckTranslation',
4c9654b4f335 CheckTranslation: add pageset selector
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 371
diff changeset
90 'language': lang,
4c9654b4f335 CheckTranslation: add pageset selector
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 371
diff changeset
91 'pageset': _pageset_name, })
4c9654b4f335 CheckTranslation: add pageset selector
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 371
diff changeset
92 for _pageset_name in sorted(i18n.strings.pagesets)]
4c9654b4f335 CheckTranslation: add pageset selector
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 371
diff changeset
93
4c9654b4f335 CheckTranslation: add pageset selector
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 371
diff changeset
94
4c9654b4f335 CheckTranslation: add pageset selector
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 371
diff changeset
95 pageset_selector = u''.join([fmt.paragraph(1), _("Choose:"), ' ', ' '.join(pageset_links), fmt.paragraph(0)])
4c9654b4f335 CheckTranslation: add pageset selector
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 371
diff changeset
96
370
5dbd61612452 CheckTranslation: transforming it into a real action
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 369
diff changeset
97 title = _("Checking translation '%s' for page set '%s'") % (lang, pageset_name)
5dbd61612452 CheckTranslation: transforming it into a real action
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 369
diff changeset
98 request.theme.send_title(title, page=request.page, pagename=pagename)
5dbd61612452 CheckTranslation: transforming it into a real action
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 369
diff changeset
99 request.write(request.formatter.startContent("content"))
371
36a99c8244dc CheckTranslation: adding language selector
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 370
diff changeset
100 request.write(lang_selector)
372
4c9654b4f335 CheckTranslation: add pageset selector
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 371
diff changeset
101 request.write(pageset_selector)
371
36a99c8244dc CheckTranslation: adding language selector
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 370
diff changeset
102 request.write(page_table)
370
5dbd61612452 CheckTranslation: transforming it into a real action
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 369
diff changeset
103 request.write(request.formatter.endContent())
5dbd61612452 CheckTranslation: transforming it into a real action
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 369
diff changeset
104 request.theme.send_footer(pagename)
5dbd61612452 CheckTranslation: transforming it into a real action
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 369
diff changeset
105 request.theme.send_closing_html()