def get_translations(self):
        """Returns the correct gettext translations that should be used for
        this request.  This will never fail and return a dummy translation
        object if used outside of the request or if a translation cannot be
        found.
        """
        ctx = stack.top
        if ctx is None:
            return NullTranslations()

        locale = get_locale()

        cache = self.get_translations_cache(ctx)

        translations = cache.get(str(locale))
        if translations is None:
            translations_dir = self.get_translations_path(ctx)
            translations = Translations.load(translations_dir, locale,
                                             domain=self.domain)

            # Load plugins translations
            if isinstance(translations, Translations):
                # Load core extensions translations
                from wtforms.i18n import messages_path
                wtforms_translations = Translations.load(messages_path(),
                                                         locale,
                                                         domain='wtforms')
                translations.merge(wtforms_translations)

                import flask_security
                flask_security_translations = Translations.load(
                    join(flask_security.__path__[0], 'translations'),
                    locale,
                    domain='flask_security'
                )
                translations.merge(flask_security_translations)

                for pkg in entrypoints.get_roots(current_app):
                    package = pkgutil.get_loader(pkg)
                    path = join(package.filename, 'translations')
                    domains = [f.replace(path, '').replace('.pot', '')[1:]
                               for f in iglob(join(path, '*.pot'))]
                    for domain in domains:
                        translations.merge(Translations.load(path, locale,
                                                             domain=domain))

                # Allows the theme to provide or override translations
                from . import theme

                theme_translations_dir = join(theme.current.path, 'translations')
                if exists(theme_translations_dir):
                    domain = theme.current.identifier
                    theme_translations = Translations.load(theme_translations_dir,
                                                           locale,
                                                           domain=domain)
                    translations.merge(theme_translations)

                cache[str(locale)] = translations

        return translations
def get_translations ( self ) : ctx = stack . top if ctx is None : return NullTranslations ( ) locale = get_locale ( ) cache = self . get_translations_cache ( ctx ) translations = cache . get ( str ( locale ) ) if translations is None : translations_dir = self . get_translations_path ( ctx ) translations = Translations . load ( translations_dir , locale , domain = self . domain ) if isinstance ( translations , Translations ) : from wtforms . i18n import messages_path wtforms_translations = Translations . load ( messages_path ( ) , locale , domain = 'wtforms' ) translations . merge ( wtforms_translations ) import flask_security flask_security_translations = Translations . load ( join ( flask_security . __path__ [ 0 ] , 'translations' ) , locale , domain = 'flask_security' ) translations . merge ( flask_security_translations ) for pkg in entrypoints . get_roots ( current_app ) : package = pkgutil . get_loader ( pkg ) path = join ( package . filename , 'translations' ) domains = [ f . replace ( path , '' ) . replace ( '.pot' , '' ) [ 1 : ] for f in iglob ( join ( path , '*.pot' ) ) ] for domain in domains : translations . merge ( Translations . load ( path , locale , domain = domain ) ) from . import theme theme_translations_dir = join ( theme . current . path , 'translations' ) if exists ( theme_translations_dir ) : domain = theme . current . identifier theme_translations = Translations . load ( theme_translations_dir , locale , domain = domain ) translations . merge ( theme_translations ) cache [ str ( locale ) ] = translations return translations
Returns the correct gettext translations that should be used for
        this request.  This will never fail and return a dummy translation
        object if used outside of the request or if a translation cannot be
        found.