annotate roundup/cgi/TranslationService.py @ 3696:790363e96852

Sorting/grouping by multiple properties. - Implement sorting/grouping by multiple properties for the web interface. I'm now using @sort0/@sortdir0,@sort1/@sortdir1,... and @group0/@groupdir0,... when generating URLs from a search template. These are converted to a list internally. When saving URLs (e.g. when storing queries) I'm using @sort=prop1,prop2,... and @group=... with optional '-' prepended to individual props. This means saved URLs are backward compatible with existing trackers (and yes, this was a design goal). I need the clumsy version with @sort0,@sort1 etc, because I'm currently using several selectors and checkboxes (as the classic template does, too). I don't think there is a way around that in HTML? - Updated (hopefully all) documentation to reflect the new URL format and the consequences in the web-interface. - I've set the number of sort/group properties in the classic template to two -- this can easily be reverted by changing n_sort to 1. Richard, would you look over these changes? I've set a tag before and (will set) after commit, so that it would be easy to merge out. Don't be too scared about the size of the change, most is documentation, the guts are in cgi/templating.py and small changes in the classic template.
author Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
date Wed, 30 Aug 2006 20:28:26 +0000
parents aa0316a1b2aa
children beaf7ea86e5e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2556
297dedb7226e TranslationService for Roundup templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
1 # TranslationService for Roundup templates
297dedb7226e TranslationService for Roundup templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
2 #
297dedb7226e TranslationService for Roundup templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
3 # This module is free software, you may redistribute it
297dedb7226e TranslationService for Roundup templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
4 # and/or modify under the same terms as Python.
297dedb7226e TranslationService for Roundup templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
5 #
297dedb7226e TranslationService for Roundup templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
6 # This module provides National Language Support
297dedb7226e TranslationService for Roundup templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
7 # for Roundup templating - much like roundup.i18n
297dedb7226e TranslationService for Roundup templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
8 # module for Roundup command line interface.
297dedb7226e TranslationService for Roundup templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
9 # The only difference is that translator objects
297dedb7226e TranslationService for Roundup templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
10 # returned by get_translation() have one additional
297dedb7226e TranslationService for Roundup templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
11 # method which is used by TAL engines:
297dedb7226e TranslationService for Roundup templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
12 #
297dedb7226e TranslationService for Roundup templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
13 # translate(domain, msgid, mapping, context, target_language, default)
297dedb7226e TranslationService for Roundup templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
14 #
297dedb7226e TranslationService for Roundup templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
15
2807
aa0316a1b2aa get_translation: removed 'domain' argument, added 'tracker_home' argument
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2556
diff changeset
16 __version__ = "$Revision: 1.2 $"[11:-2]
aa0316a1b2aa get_translation: removed 'domain' argument, added 'tracker_home' argument
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2556
diff changeset
17 __date__ = "$Date: 2004-10-23 14:04:23 $"[7:-2]
2556
297dedb7226e TranslationService for Roundup templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
18
297dedb7226e TranslationService for Roundup templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
19 from roundup import i18n
297dedb7226e TranslationService for Roundup templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
20 from roundup.cgi.PageTemplates import Expressions, PathIterator, TALES
297dedb7226e TranslationService for Roundup templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
21 from roundup.cgi.TAL import TALInterpreter
297dedb7226e TranslationService for Roundup templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
22
297dedb7226e TranslationService for Roundup templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
23 ### Translation classes
297dedb7226e TranslationService for Roundup templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
24
297dedb7226e TranslationService for Roundup templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
25 class TranslationServiceMixin:
297dedb7226e TranslationService for Roundup templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
26
297dedb7226e TranslationService for Roundup templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
27 OUTPUT_ENCODING = "utf-8"
297dedb7226e TranslationService for Roundup templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
28
297dedb7226e TranslationService for Roundup templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
29 def translate(self, domain, msgid, mapping=None,
297dedb7226e TranslationService for Roundup templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
30 context=None, target_language=None, default=None
297dedb7226e TranslationService for Roundup templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
31 ):
297dedb7226e TranslationService for Roundup templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
32 _msg = self.gettext(msgid)
297dedb7226e TranslationService for Roundup templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
33 #print ("TRANSLATE", msgid, _msg, mapping, context)
297dedb7226e TranslationService for Roundup templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
34 _msg = TALInterpreter.interpolate(_msg, mapping)
297dedb7226e TranslationService for Roundup templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
35 return _msg
297dedb7226e TranslationService for Roundup templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
36
297dedb7226e TranslationService for Roundup templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
37 def gettext(self, msgid):
297dedb7226e TranslationService for Roundup templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
38 return self.ugettext(msgid).encode(self.OUTPUT_ENCODING)
297dedb7226e TranslationService for Roundup templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
39
297dedb7226e TranslationService for Roundup templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
40 def ngettext(self, singular, plural, number):
297dedb7226e TranslationService for Roundup templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
41 return self.ungettext(singular, plural, number).encode(
297dedb7226e TranslationService for Roundup templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
42 self.OUTPUT_ENCODING)
297dedb7226e TranslationService for Roundup templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
43
297dedb7226e TranslationService for Roundup templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
44 class TranslationService(TranslationServiceMixin, i18n.RoundupTranslations):
297dedb7226e TranslationService for Roundup templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
45 pass
297dedb7226e TranslationService for Roundup templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
46
297dedb7226e TranslationService for Roundup templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
47 class NullTranslationService(TranslationServiceMixin,
297dedb7226e TranslationService for Roundup templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
48 i18n.RoundupNullTranslations
297dedb7226e TranslationService for Roundup templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
49 ):
297dedb7226e TranslationService for Roundup templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
50 pass
297dedb7226e TranslationService for Roundup templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
51
297dedb7226e TranslationService for Roundup templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
52 ### TAL patching
297dedb7226e TranslationService for Roundup templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
53 #
297dedb7226e TranslationService for Roundup templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
54 # Template Attribute Language (TAL) uses only global translation service,
297dedb7226e TranslationService for Roundup templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
55 # which is not thread-safe. We will use context variable 'i18n'
297dedb7226e TranslationService for Roundup templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
56 # to access request-dependent transalation service (with domain
297dedb7226e TranslationService for Roundup templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
57 # and target language set during initializations of the roundup
297dedb7226e TranslationService for Roundup templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
58 # client interface.
297dedb7226e TranslationService for Roundup templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
59 #
297dedb7226e TranslationService for Roundup templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
60
297dedb7226e TranslationService for Roundup templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
61 class Context(TALES.Context):
297dedb7226e TranslationService for Roundup templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
62
297dedb7226e TranslationService for Roundup templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
63 def __init__(self, compiler, contexts):
297dedb7226e TranslationService for Roundup templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
64 TALES.Context.__init__(self, compiler, contexts)
297dedb7226e TranslationService for Roundup templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
65 if not self.contexts.get('i18n', None):
297dedb7226e TranslationService for Roundup templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
66 # if the context contains no TranslationService,
297dedb7226e TranslationService for Roundup templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
67 # create default one
297dedb7226e TranslationService for Roundup templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
68 self.contexts['i18n'] = get_translation()
297dedb7226e TranslationService for Roundup templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
69 self.i18n = self.contexts['i18n']
297dedb7226e TranslationService for Roundup templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
70
297dedb7226e TranslationService for Roundup templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
71 def translate(self, domain, msgid, mapping=None,
297dedb7226e TranslationService for Roundup templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
72 context=None, target_language=None, default=None):
297dedb7226e TranslationService for Roundup templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
73 if context is None:
297dedb7226e TranslationService for Roundup templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
74 context = self.contexts.get('here')
297dedb7226e TranslationService for Roundup templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
75 return self.i18n.translate(domain, msgid,
297dedb7226e TranslationService for Roundup templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
76 mapping=mapping, context=context, default=default,
297dedb7226e TranslationService for Roundup templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
77 target_language=target_language)
297dedb7226e TranslationService for Roundup templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
78
297dedb7226e TranslationService for Roundup templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
79 class Engine(TALES.Engine):
297dedb7226e TranslationService for Roundup templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
80
297dedb7226e TranslationService for Roundup templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
81 def getContext(self, contexts=None, **kwcontexts):
297dedb7226e TranslationService for Roundup templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
82 if contexts is not None:
297dedb7226e TranslationService for Roundup templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
83 if kwcontexts:
297dedb7226e TranslationService for Roundup templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
84 kwcontexts.update(contexts)
297dedb7226e TranslationService for Roundup templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
85 else:
297dedb7226e TranslationService for Roundup templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
86 kwcontexts = contexts
297dedb7226e TranslationService for Roundup templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
87 return Context(self, kwcontexts)
297dedb7226e TranslationService for Roundup templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
88
297dedb7226e TranslationService for Roundup templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
89 # patching TAL like this is a dirty hack,
297dedb7226e TranslationService for Roundup templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
90 # but i see no other way to specify different Context class
297dedb7226e TranslationService for Roundup templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
91 Expressions._engine = Engine(PathIterator.Iterator)
297dedb7226e TranslationService for Roundup templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
92 Expressions.installHandlers(Expressions._engine)
297dedb7226e TranslationService for Roundup templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
93
297dedb7226e TranslationService for Roundup templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
94 ### main API function
297dedb7226e TranslationService for Roundup templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
95
2807
aa0316a1b2aa get_translation: removed 'domain' argument, added 'tracker_home' argument
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2556
diff changeset
96 def get_translation(language=None, tracker_home=None,
2556
297dedb7226e TranslationService for Roundup templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
97 translation_class=TranslationService,
297dedb7226e TranslationService for Roundup templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
98 null_translation_class=NullTranslationService
297dedb7226e TranslationService for Roundup templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
99 ):
297dedb7226e TranslationService for Roundup templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
100 """Return Translation object for given language and domain
297dedb7226e TranslationService for Roundup templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
101
297dedb7226e TranslationService for Roundup templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
102 Arguments 'translation_class' and 'null_translation_class'
297dedb7226e TranslationService for Roundup templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
103 specify the classes that are instantiated for existing
297dedb7226e TranslationService for Roundup templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
104 and non-existing translations, respectively.
297dedb7226e TranslationService for Roundup templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
105 """
2807
aa0316a1b2aa get_translation: removed 'domain' argument, added 'tracker_home' argument
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2556
diff changeset
106 return i18n.get_translation(language=language,
aa0316a1b2aa get_translation: removed 'domain' argument, added 'tracker_home' argument
Alexander Smishlajev <a1s@users.sourceforge.net>
parents: 2556
diff changeset
107 tracker_home=tracker_home,
2556
297dedb7226e TranslationService for Roundup templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
108 translation_class=translation_class,
297dedb7226e TranslationService for Roundup templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
109 null_translation_class=null_translation_class)
297dedb7226e TranslationService for Roundup templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
110
297dedb7226e TranslationService for Roundup templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff changeset
111 # vim: set et sts=4 sw=4 :

Roundup Issue Tracker: http://roundup-tracker.org/