Logo Search packages:      
Sourcecode: zope-cps-translationservice version File versions  Download package

def TranslationService::Domain::Domain::translate (   self,
  msgid,
  mapping = None,
  context = None,
  target_language = None,
  default = None 
)

Translate a msgid, maybe doing ${keyword} substitution.

msgid is the message id to be translated.
mapping is a set of mapping to be applied on ${keywords}.

Definition at line 77 of file Domain.py.

                                                     :
        """Translate a msgid, maybe doing ${keyword} substitution.

        msgid is the message id to be translated.
        mapping is a set of mapping to be applied on ${keywords}.
        """
        # msgid can be '${name} was born in ${country}'.
        # mapping can be {'country': 'Antarctica', 'name': 'Lomax'}.
        # context must be adaptable to IUserPreferredLanguages.

        mc = self.getMessageCatalog(lang=target_language)
        text = mc.queryMessage(msgid, default=default)
        if text is None:
            # No default was passed, and msgid has no translation.
            # We'll get what's in between the tags where the translate
            # has been invoked within the template
            if default is None:
                default = msgid
            res = self.noTranslation(mapping=mapping, default=default)
        else:
            res = self._interpolate(text, mapping)
        # Make sure we always return unicode
        if not isinstance(res, unicode):
            # This can happen if a non-unicode default is passed
            res = unicode(res, 'iso-8859-15')
        return res

    #
    # Internal


Generated by  Doxygen 1.6.0   Back to index