Пример #1
0
    def _get_translation(self):
        lang = validate_language(get_lang())
        paths = cherrypy.request.app.root.paths
        domain = cherrypy.request.app.root.domain
        messages = cherrypy.request.app.root.messages
        text = messages.get(self.code, self.code)

        try:
            translation = gettext.translation(domain, paths.mo_dir, [lang])
        except:
            translation = gettext

        return translation.gettext(text)
Пример #2
0
    def _get_translation(self):
        lang = validate_language(get_lang())
        paths = cherrypy.request.app.root.paths
        domain = cherrypy.request.app.root.domain
        messages = cherrypy.request.app.root.messages
        text = messages.get(self.code, self.code)

        try:
            translation = gettext.translation(domain, paths.mo_dir, [lang])
        except:
            translation = gettext

        return translation.gettext(text)
Пример #3
0
    def _get_translation(self, args):
        lang = validate_language(get_lang())
        paths = cherrypy.request.app.root.paths
        domain = cherrypy.request.app.root.domain
        messages = cherrypy.request.app.root.messages
        text = messages.get(self.code, self.code)

        try:
            translation = gettext.translation(domain, paths.mo_dir, [lang])
        except:
            translation = gettext

        for key, value in args.iteritems():
            if not isinstance(value, unicode):
                args[key] = unicode(value, 'utf-8')

        return unicode(translation.gettext(text), 'utf-8') % args
Пример #4
0
    def _get_translation(self, args):
        lang = validate_language(get_lang())
        paths = cherrypy.request.app.root.paths
        domain = cherrypy.request.app.root.domain
        messages = cherrypy.request.app.root.messages
        text = messages.get(self.code, self.code)

        try:
            translation = gettext.translation(domain, paths.mo_dir, [lang])
        except:
            translation = gettext

        for key, value in args.iteritems():
            if not isinstance(value, unicode):
                args[key] = unicode(value, 'utf-8')

        return unicode(translation.gettext(text), 'utf-8') % args
Пример #5
0
    def __init__(self, code='', args={}):
        lang = validate_language(get_lang())
        paths = cherrypy.request.app.root.paths
        domain = cherrypy.request.app.root.domain
        messages = cherrypy.request.app.root.messages
        text = messages.get(code, code)

        try:
            translation = gettext.translation(domain, paths.mo_dir, [lang])
        except:
            translation = gettext

        for key, value in args.iteritems():
            if not isinstance(value, unicode):
                args[key] = unicode(value, 'utf-8')

        msg = unicode(translation.gettext(text), 'utf-8') % args
        pattern = "%s: %s" % (code, msg)
        Exception.__init__(self, pattern)
Пример #6
0
    def _get_translation(self, args):
        lang = validate_language(get_lang())
        paths = cherrypy.request.app.root.paths
        domain = cherrypy.request.app.root.domain
        messages = cherrypy.request.app.root.messages
        text = messages.get(self.code, self.code)

        try:
            translation = gettext.translation(domain, paths.mo_dir, [lang])
        except:
            translation = gettext

        for key, value in args.iteritems():
            if not isinstance(value, unicode):
                try:
                    # In case the value formats itself to an ascii string.
                    args[key] = unicode(str(value), 'utf-8')
                except UnicodeEncodeError:
                    # In case the value is a KimchiException or it formats
                    # itself to a unicode string.
                    args[key] = unicode(value)

        return unicode(translation.gettext(text), 'utf-8') % args
Пример #7
0
    def _get_translation(self, args):
        lang = validate_language(get_lang())
        paths = cherrypy.request.app.root.paths
        domain = cherrypy.request.app.root.domain
        messages = cherrypy.request.app.root.messages
        text = messages.get(self.code, self.code)

        try:
            translation = gettext.translation(domain, paths.mo_dir, [lang])
        except:
            translation = gettext

        for key, value in args.iteritems():
            if not isinstance(value, unicode):
                try:
                    # In case the value formats itself to an ascii string.
                    args[key] = unicode(str(value), 'utf-8')
                except UnicodeEncodeError:
                    # In case the value is a KimchiException or it formats
                    # itself to a unicode string.
                    args[key] = unicode(value)

        return unicode(translation.gettext(text), 'utf-8') % args