Mercurial > p > roundup > code
diff roundup/cgi/TranslationService.py @ 6200:718f205dbe50
pep8 fixes.
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Fri, 19 Jun 2020 21:34:21 -0400 |
| parents | b0c2307be3d1 |
| children | 07ce4e4110f5 |
line wrap: on
line diff
--- a/roundup/cgi/TranslationService.py Sat Jun 13 00:19:38 2020 -0400 +++ b/roundup/cgi/TranslationService.py Fri Jun 19 21:34:21 2020 -0400 @@ -20,11 +20,11 @@ ### Translation classes + class TranslationServiceMixin: 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) #print ("TRANSLATE", msgid, _msg, mapping, context) _msg = TALInterpreter.interpolate(_msg, mapping) @@ -33,20 +33,22 @@ if hasattr(i18n.RoundupTranslations, 'ugettext'): def gettext(self, msgid): msgid = us2u(msgid) - msgtrans=self.ugettext(msgid) + msgtrans = self.ugettext(msgid) return u2s(msgtrans) def ngettext(self, singular, plural, number): singular = us2u(singular) plural = us2u(plural) - msgtrans=self.ungettext(singular, plural, number) + msgtrans = self.ungettext(singular, plural, number) return u2s(msgtrans) + class TranslationService(TranslationServiceMixin, i18n.RoundupTranslations): pass + class NullTranslationService(TranslationServiceMixin, - i18n.RoundupNullTranslations): + i18n.RoundupNullTranslations): if hasattr(i18n.RoundupNullTranslations, 'ugettext'): def ugettext(self, message): if self._fallback: @@ -65,6 +67,7 @@ # client interface. # + class Context(TALES.Context): def __init__(self, compiler, contexts): @@ -80,8 +83,10 @@ if context is None: context = self.contexts.get('here') return self.i18n.translate(domain, msgid, - mapping=mapping, context=context, default=default, - target_language=target_language) + mapping=mapping, context=context, + default=default, + target_language=target_language) + class Engine(TALES.Engine): @@ -93,6 +98,7 @@ kwcontexts = contexts return Context(self, kwcontexts) + # patching TAL like this is a dirty hack, # but i see no other way to specify different Context class Expressions._engine = Engine(PathIterator.Iterator) @@ -100,10 +106,10 @@ ### main API function + def get_translation(language=None, tracker_home=None, - translation_class=TranslationService, - null_translation_class=NullTranslationService -): + translation_class=TranslationService, + null_translation_class=NullTranslationService): """Return Translation object for given language and domain Arguments 'translation_class' and 'null_translation_class' @@ -111,8 +117,8 @@ and non-existing translations, respectively. """ return i18n.get_translation(language=language, - tracker_home=tracker_home, - translation_class=translation_class, - null_translation_class=null_translation_class) + tracker_home=tracker_home, + translation_class=translation_class, + null_translation_class=null_translation_class) # vim: set et sts=4 sw=4 :
