"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "roundup/cgi/TranslationService.py" between
roundup-1.6.1.tar.gz and roundup-2.0.0.tar.gz

About: Roundup is an highly customisable issue-tracking system with command-line, web and e-mail interfaces (written in Python).

TranslationService.py  (roundup-1.6.1):TranslationService.py  (roundup-2.0.0)
skipping to change at line 19 skipping to change at line 19
# The only difference is that translator objects # The only difference is that translator objects
# returned by get_translation() have one additional # returned by get_translation() have one additional
# method which is used by TAL engines: # method which is used by TAL engines:
# #
# translate(domain, msgid, mapping, context, target_language, default) # translate(domain, msgid, mapping, context, target_language, default)
# #
from roundup import i18n from roundup import i18n
from roundup.cgi.PageTemplates import Expressions, PathIterator, TALES from roundup.cgi.PageTemplates import Expressions, PathIterator, TALES
from roundup.cgi.TAL import TALInterpreter from roundup.cgi.TAL import TALInterpreter
from roundup.anypy.strings import us2u, u2s
### Translation classes ### Translation classes
class TranslationServiceMixin: class TranslationServiceMixin:
OUTPUT_ENCODING = "utf-8"
def translate(self, domain, msgid, mapping=None, def translate(self, domain, msgid, mapping=None,
context=None, target_language=None, default=None context=None, target_language=None, default=None):
):
_msg = self.gettext(msgid) _msg = self.gettext(msgid)
#print ("TRANSLATE", msgid, _msg, mapping, context) #print ("TRANSLATE", msgid, _msg, mapping, context)
_msg = TALInterpreter.interpolate(_msg, mapping) _msg = TALInterpreter.interpolate(_msg, mapping)
return _msg return _msg
def gettext(self, msgid): if hasattr(i18n.RoundupTranslations, 'ugettext'):
if not isinstance(msgid, unicode): def gettext(self, msgid):
msgid = unicode(msgid, 'utf8') msgid = us2u(msgid)
msgtrans=self.ugettext(msgid) msgtrans = self.ugettext(msgid)
return msgtrans.encode(self.OUTPUT_ENCODING) return u2s(msgtrans)
def ngettext(self, singular, plural, number): def ngettext(self, singular, plural, number):
if not isinstance(singular, unicode): singular = us2u(singular)
singular = unicode(singular, 'utf8') plural = us2u(plural)
if not isinstance(plural, unicode): msgtrans = self.ungettext(singular, plural, number)
plural = unicode(plural, 'utf8') return u2s(msgtrans)
msgtrans=self.ungettext(singular, plural, number)
return msgtrans.encode(self.OUTPUT_ENCODING)
class TranslationService(TranslationServiceMixin, i18n.RoundupTranslations): class TranslationService(TranslationServiceMixin, i18n.RoundupTranslations):
pass pass
class NullTranslationService(TranslationServiceMixin, class NullTranslationService(TranslationServiceMixin,
i18n.RoundupNullTranslations): i18n.RoundupNullTranslations):
def ugettext(self, message): if hasattr(i18n.RoundupNullTranslations, 'ugettext'):
if self._fallback: def ugettext(self, message):
return self._fallback.ugettext(message) if self._fallback:
# Sometimes the untranslatable message is a UTF-8 encoded string return self._fallback.ugettext(message)
# (thanks to PageTemplate's internals). # Sometimes the untranslatable message is a UTF-8 encoded string
if not isinstance(message, unicode): # (thanks to PageTemplate's internals).
return unicode(message, 'utf8') message = us2u(message)
return message return message
### TAL patching ### TAL patching
# #
# Template Attribute Language (TAL) uses only global translation service, # Template Attribute Language (TAL) uses only global translation service,
# which is not thread-safe. We will use context variable 'i18n' # which is not thread-safe. We will use context variable 'i18n'
# to access request-dependent transalation service (with domain # to access request-dependent transalation service (with domain
# and target language set during initializations of the roundup # and target language set during initializations of the roundup
# client interface. # client interface.
# #
skipping to change at line 86 skipping to change at line 82
# if the context contains no TranslationService, # if the context contains no TranslationService,
# create default one # create default one
self.contexts['i18n'] = get_translation() self.contexts['i18n'] = get_translation()
self.i18n = self.contexts['i18n'] self.i18n = self.contexts['i18n']
def translate(self, domain, msgid, mapping=None, def translate(self, domain, msgid, mapping=None,
context=None, target_language=None, default=None): context=None, target_language=None, default=None):
if context is None: if context is None:
context = self.contexts.get('here') context = self.contexts.get('here')
return self.i18n.translate(domain, msgid, return self.i18n.translate(domain, msgid,
mapping=mapping, context=context, default=default, mapping=mapping, context=context,
target_language=target_language) default=default,
target_language=target_language)
class Engine(TALES.Engine): class Engine(TALES.Engine):
def getContext(self, contexts=None, **kwcontexts): def getContext(self, contexts=None, **kwcontexts):
if contexts is not None: if contexts is not None:
if kwcontexts: if kwcontexts:
kwcontexts.update(contexts) kwcontexts.update(contexts)
else: else:
kwcontexts = contexts kwcontexts = contexts
return Context(self, kwcontexts) return Context(self, kwcontexts)
# patching TAL like this is a dirty hack, # patching TAL like this is a dirty hack,
# but i see no other way to specify different Context class # but i see no other way to specify different Context class
Expressions._engine = Engine(PathIterator.Iterator) Expressions._engine = Engine(PathIterator.Iterator)
Expressions.installHandlers(Expressions._engine) Expressions.installHandlers(Expressions._engine)
### main API function ### main API function
def get_translation(language=None, tracker_home=None, def get_translation(language=None, tracker_home=None,
translation_class=TranslationService, translation_class=TranslationService,
null_translation_class=NullTranslationService null_translation_class=NullTranslationService):
):
"""Return Translation object for given language and domain """Return Translation object for given language and domain
Arguments 'translation_class' and 'null_translation_class' Arguments 'translation_class' and 'null_translation_class'
specify the classes that are instantiated for existing specify the classes that are instantiated for existing
and non-existing translations, respectively. and non-existing translations, respectively.
""" """
return i18n.get_translation(language=language, return i18n.get_translation(language=language,
tracker_home=tracker_home, tracker_home=tracker_home,
translation_class=translation_class, translation_class=translation_class,
null_translation_class=null_translation_class) null_translation_class=null_translation_class)
# vim: set et sts=4 sw=4 : # vim: set et sts=4 sw=4 :
 End of changes. 8 change blocks. 
34 lines changed or deleted 30 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)