Esempio n. 1
0
    def _get_translation(self):
        wok_app = cherrypy.tree.apps.get('', None)

        # get app from plugin path if specified
        if self.plugin:
            app = cherrypy.tree.apps.get(self.plugin, None)
        # if on request, try to get app from it
        elif cherrypy.request.app:
            app = cherrypy.request.app
        # fallback: get root app (WokRoot)
        else:
            app = wok_app

        if app is None:
            return self.code

        # fallback to Wok message in case plugins raise Wok exceptions
        text = app.root.messages.get(self.code, self.code)
        if text == self.code and wok_app is not None:
            app = wok_app
            text = app.root.messages.get(self.code, self.code)

        # do translation
        domain = app.root.domain
        paths = app.root.paths
        lang = validate_language(get_lang())

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

        return translation.gettext(text)
Esempio n. 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)
Esempio n. 3
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)