def set_store(store, key=_store_registry_key, app=None): """Sets an instance of :class:`I18nStore` in the app registry. :param store: An instance of :class:`I18nStore`. :param key: The key used to retrieve the instance from the registry. A default is used if it is not set. :param request: A :class:`webapp3.WSGIApplication` instance used to retrieve the instance. The active app is used if it is not set. """ app = app or webapp3.get_app() app.registry[key] = store
def get_translations(self, locale): """Returns a translation catalog for a locale. :param locale: A locale code. :returns: A ``babel.support.Translations`` instance, or ``gettext.NullTranslations`` if none was found. """ trans = self.translations.get(locale) if not trans: locales = (locale, self.default_locale) trans = self.load_translations(self.translations_path, locales, self.domains) if not webapp3.get_app().debug: self.translations[locale] = trans return trans
def get_store(factory=I18nStore, key=_store_registry_key, app=None): """Returns an instance of :class:`I18nStore` from the app registry. It'll try to get it from the current app registry, and if it is not registered it'll be instantiated and registered. A second call to this function will return the same instance. :param factory: The callable used to build and register the instance if it is not yet registered. The default is the class :class:`I18nStore` itself. :param key: The key used to store the instance in the registry. A default is used if it is not set. :param app: A :class:`webapp3.WSGIApplication` instance used to store the instance. The active app is used if it is not set. """ app = app or webapp3.get_app() store = app.registry.get(key) if not store: store = app.registry[key] = factory(app) return store