From 8c4dbb9644b98761041fd1024e500694dc588e93 Mon Sep 17 00:00:00 2001 From: Tyler Kennedy Date: Wed, 26 Aug 2020 23:18:16 -0400 Subject: [PATCH 1/4] Remove unused git submodule (old way of installing sphinx theme) --- .gitmodules | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 .gitmodules diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index bf7b494..0000000 --- a/.gitmodules +++ /dev/null @@ -1,3 +0,0 @@ -[submodule "docs/_themes"] - path = docs/_themes - url = git://github.com/mitsuhiko/flask-sphinx-themes.git From 06d7a9ac79a3b5f77d533b15735537586ef4beda Mon Sep 17 00:00:00 2001 From: Tyler Kennedy Date: Wed, 26 Aug 2020 23:46:48 -0400 Subject: [PATCH 2/4] Resolve minor flake8 issues. --- flask_babel/__init__.py | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/flask_babel/__init__.py b/flask_babel/__init__.py index c51b2ef..a64b0e6 100644 --- a/flask_babel/__init__.py +++ b/flask_babel/__init__.py @@ -522,7 +522,10 @@ def __init__(self, translation_directories=None, domain='messages'): self.cache = {} def __repr__(self): - return ''.format(self._translation_directories, self.domain) + return ''.format( + self._translation_directories, + self.domain + ) @property def translation_directories(self): @@ -565,9 +568,9 @@ def get_translations(self): ) translations.merge(catalog) # FIXME: Workaround for merge() being really, really stupid. It - # does not copy _info, plural(), or any other instance variables - # populated by GNUTranslations. We probably want to stop using - # `support.Translations.merge` entirely. + # does not copy _info, plural(), or any other instance + # variables populated by GNUTranslations. We probably want to + # stop using `support.Translations.merge` entirely. if hasattr(catalog, 'plural'): translations.plural = catalog.plural @@ -629,7 +632,7 @@ def lazy_gettext(self, string, **variables): Example:: - hello = lazy_gettext(u'Hello World') + hello = lazy_gettext('Hello World') @app.route('/') def index(): @@ -643,7 +646,11 @@ def lazy_ngettext(self, singular, plural, num, **variables): Example:: - apples = lazy_ngettext(u'%(num)d Apple', u'%(num)d Apples', num=len(apples)) + apples = lazy_ngettext( + '%(num)d Apple', + '%(num)d Apples', + num=len(apples) + ) @app.route('/') def index(): @@ -687,6 +694,8 @@ def get_domain(): # Create shortcuts for the default Flask domain def gettext(*args, **kwargs): return get_domain().gettext(*args, **kwargs) + + _ = gettext From 84ebb861544db4ce3fff657dd3d989f3364732a7 Mon Sep 17 00:00:00 2001 From: Tyler Kennedy Date: Thu, 27 Aug 2020 21:09:45 -0400 Subject: [PATCH 3/4] Start stripping out format_ methods. (#164) Also start working on new documentation (#173) --- docs/index.rst | 196 ++++--------------- flask_babel/__init__.py | 413 ++++------------------------------------ 2 files changed, 79 insertions(+), 530 deletions(-) diff --git a/docs/index.rst b/docs/index.rst index 442932f..8a0641c 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -3,11 +3,7 @@ Flask-Babel .. module:: flask_babel -Flask-Babel is an extension to `Flask`_ that adds i18n and l10n support to -any Flask application with the help of `babel`_, `pytz`_ and -`speaklater`_. It has builtin support for date formatting with timezone -support as well as a very simple and friendly interface to :mod:`gettext` -translations. +Easy integration of `Flask`_ and `babel`_. Installation ------------ @@ -35,9 +31,9 @@ object after configuring the application:: babel = Babel(app) To disable jinja support, include ``configure_jinja=False`` in the Babel -constructor call. The babel object itself can be used to configure the babel support -further. Babel has the following configuration values that can be used to -change some internal defaults: +constructor call. The babel object itself can be used to configure the babel +support further. Babel has the following configuration values that can be used +to change some internal defaults: =============================== ============================================= `BABEL_DEFAULT_LOCALE` The default locale to use if no locale @@ -72,7 +68,7 @@ Example selector functions:: from flask import g, request @babel.localeselector - def get_locale(): + def get_user_locale(): # if a user is logged in, use the locale from the user settings user = getattr(g, 'user', None) if user is not None: @@ -83,7 +79,7 @@ Example selector functions:: return request.accept_languages.best_match(['de', 'fr', 'en']) @babel.timezoneselector - def get_timezone(): + def get_user_timezone(): user = getattr(g, 'user', None) if user is not None: return user.timezone @@ -91,122 +87,6 @@ Example selector functions:: The example above assumes that the current user is stored on the :data:`flask.g` object. -Jinja Filters -------------- - -Several commonly used formatters are added as jinja template filters after -calling `init_app().` For dates and times, these are: - -- `|datetimeformat` -> `format_datetime` -- `|dateformat` -> `format_date` -- `