--- env/lib/python2.7/site-packages/flask_babel/__init__.py 2013-07-13 00:00:00 +0000 +++ env/lib/python2.7/site-packages/flask_babel/__init__.py 2013-07-13 00:00:00 +0000 @@ -19,6 +19,7 @@ from datetime import datetime from flask import _request_ctx_stack from babel import dates, numbers, support, Locale +from gettext import NullTranslations from werkzeug import ImmutableDict try: from pytz.gae import pytz @@ -55,9 +56,11 @@ }) def __init__(self, app=None, default_locale='en', default_timezone='UTC', - date_formats=None, configure_jinja=True): + date_formats=None, configure_jinja=True, + default_domain=support.Translations.DEFAULT_DOMAIN): self._default_locale = default_locale self._default_timezone = default_timezone + self._default_domain = default_domain self._date_formats = date_formats self._configure_jinja = configure_jinja self.app = app @@ -77,6 +80,7 @@ app.config.setdefault('BABEL_DEFAULT_LOCALE', self._default_locale) app.config.setdefault('BABEL_DEFAULT_TIMEZONE', self._default_timezone) + app.config.setdefault('BABEL_DEFAULT_DOMAIN', self._default_domain) if self._date_formats is None: self._date_formats = self.default_date_formats.copy() @@ -95,6 +99,7 @@ self.locale_selector_func = None self.timezone_selector_func = None + self.domain_selector_func = None if self._configure_jinja: app.jinja_env.filters.update( @@ -142,6 +147,19 @@ self.timezone_selector_func = f return f + def domainselector(self, f): + """Registers a callback function for domain selection. The default + behaves as if a function was registered that returns `None` all the + time. If `None` is returned, the domain falls back to the one from + the configuration. + + This has to return the domain as a list of strings (eg: ``['messages']``) + """ + assert self.domain_selector_func is None, \ + 'a localeselector function is already registered' + self.domain_selector_func = f + return f + def list_translations(self): """Returns a list of all the locales translations exist for. The @@ -178,6 +196,13 @@ """ return timezone(self.app.config['BABEL_DEFAULT_TIMEZONE']) + @property + def default_domain(self): + """The default domain from the configuration as instance of a + `string` object. + """ + return self.app.config['BABEL_DEFAULT_DOMAIN'] + def get_translations(): """Returns the correct gettext translations that should be used for @@ -191,7 +216,10 @@ translations = getattr(ctx, 'babel_translations', None) if translations is None: dirname = os.path.join(ctx.app.root_path, 'translations') - translations = support.Translations.load(dirname, [get_locale()]) + locale = get_locale() + for domain in get_domains(): + dt = support.Translations.load(dirname, [locale], domain) + translations = dt if translations is None or not hasattr(translations, 'merge') else translations.merge(dt) ctx.babel_translations = translations return translations @@ -243,6 +271,29 @@ return tzinfo +def HTTP/1.1 200 OK Cache-Control: public, max-age=21600, no-transform Last-Modified: Thu, 13 Feb 2014 20:58:13 GMT Set-Cookie: i_like_gitea=41e22c6bd50fc3a1; Path=/; HttpOnly; Secure; SameSite=Lax Set-Cookie: _csrf=lplut8R1QTcWLPH_shWmIYCACIw6MTc1MzI2NTcwMDk3NDcyMjA4OA; Path=/; Max-Age=86400; HttpOnly; Secure; SameSite=Lax Content-Length: 4256 Content-Type: text/plain; charset=utf-8 X-Content-Type-Options: nosniff Date: Wed, 23 Jul 2025 10:15:01 GMT Etag: "404f9208b7cf10ca7f63413c1790aea2a40f290b" X-Frame-Options: SAMEORIGIN Connection: close Access-Control-Expose-Headers: Content-Disposition Content-Disposition: inline; filename="multi-domain.patch"; filename*=UTF-8''multi-domain.patch X-Cache-Status: HIT X-Cache-Age: 0 --- env/lib/python2.7/site-packages/flask_babel/__init__.py 2013-07-13 00:00:00 +0000 +++ env/lib/python2.7/site-packages/f