2020
2121### Translation classes
2222
23+
2324class TranslationServiceMixin :
2425
2526 def translate (self , domain , msgid , mapping = None ,
26- context = None , target_language = None , default = None
27- ):
27+ context = None , target_language = None , default = None ):
2828 _msg = self .gettext (msgid )
2929 #print ("TRANSLATE", msgid, _msg, mapping, context)
3030 _msg = TALInterpreter .interpolate (_msg , mapping )
@@ -33,20 +33,22 @@ def translate(self, domain, msgid, mapping=None,
3333 if hasattr (i18n .RoundupTranslations , 'ugettext' ):
3434 def gettext (self , msgid ):
3535 msgid = us2u (msgid )
36- msgtrans = self .ugettext (msgid )
36+ msgtrans = self .ugettext (msgid )
3737 return u2s (msgtrans )
3838
3939 def ngettext (self , singular , plural , number ):
4040 singular = us2u (singular )
4141 plural = us2u (plural )
42- msgtrans = self .ungettext (singular , plural , number )
42+ msgtrans = self .ungettext (singular , plural , number )
4343 return u2s (msgtrans )
4444
45+
4546class TranslationService (TranslationServiceMixin , i18n .RoundupTranslations ):
4647 pass
4748
49+
4850class NullTranslationService (TranslationServiceMixin ,
49- i18n .RoundupNullTranslations ):
51+ i18n .RoundupNullTranslations ):
5052 if hasattr (i18n .RoundupNullTranslations , 'ugettext' ):
5153 def ugettext (self , message ):
5254 if self ._fallback :
@@ -65,6 +67,7 @@ def ugettext(self, message):
6567# client interface.
6668#
6769
70+
6871class Context (TALES .Context ):
6972
7073 def __init__ (self , compiler , contexts ):
@@ -80,8 +83,10 @@ def translate(self, domain, msgid, mapping=None,
8083 if context is None :
8184 context = self .contexts .get ('here' )
8285 return self .i18n .translate (domain , msgid ,
83- mapping = mapping , context = context , default = default ,
84- target_language = target_language )
86+ mapping = mapping , context = context ,
87+ default = default ,
88+ target_language = target_language )
89+
8590
8691class Engine (TALES .Engine ):
8792
@@ -93,26 +98,27 @@ def getContext(self, contexts=None, **kwcontexts):
9398 kwcontexts = contexts
9499 return Context (self , kwcontexts )
95100
101+
96102# patching TAL like this is a dirty hack,
97103# but i see no other way to specify different Context class
98104Expressions ._engine = Engine (PathIterator .Iterator )
99105Expressions .installHandlers (Expressions ._engine )
100106
101107### main API function
102108
109+
103110def get_translation (language = None , tracker_home = None ,
104- translation_class = TranslationService ,
105- null_translation_class = NullTranslationService
106- ):
111+ translation_class = TranslationService ,
112+ null_translation_class = NullTranslationService ):
107113 """Return Translation object for given language and domain
108114
109115 Arguments 'translation_class' and 'null_translation_class'
110116 specify the classes that are instantiated for existing
111117 and non-existing translations, respectively.
112118 """
113119 return i18n .get_translation (language = language ,
114- tracker_home = tracker_home ,
115- translation_class = translation_class ,
116- null_translation_class = null_translation_class )
120+ tracker_home = tracker_home ,
121+ translation_class = translation_class ,
122+ null_translation_class = null_translation_class )
117123
118124# vim: set et sts=4 sw=4 :
0 commit comments