i18n and l10n support for Flask based on Babel and pytz

Related tags

Flaskflask-babel
Overview

Flask Babel

Tests PyPI

Implements i18n and l10n support for Flask. This is based on the Python babel module as well as pytz both of which are installed automatically for you if you install this library.

Documention

The latest documentation is available here.

Comments
  • Support temporary language switch inside a request

    Support temporary language switch inside a request

    It would be nice to be able to stash the current language somewhere and use another one for a while during a request execution.

    The main use-case I see is sending out emails with Flask-Email. The email should be translated according to the recipient's language and not the current user's language.

    Something like:

    from flaskext.babel import stash, unstash
    
    # do stuff with current user's language
    print _('foo')
    # Now switch to th recipient language
    stash(new_lang=recipient.language)
    send email with i18n tags
    unstash()
    # Now the language is back to the current user's lang
    

    Well the API is terrible, but you get the idea..

    opened by rslinckx 14
  • do not hardcode the translations folder path

    do not hardcode the translations folder path

    This allows to specify in which folder the translations should be looked for instead of having it hardcoded (still defaults to "translations"). This is done either via a folder param passed to the constructor or via the BABEL_TRANSLATIONS_FOLDER configuration variable.

    opened by mdeous 13
  • pybabel fails to update under python-3.3

    pybabel fails to update under python-3.3

    TypeError is being thrown:

    $ pybabel update -i messages.pot -d translations/
    updating catalog 'translations/en/LC_MESSAGES/messages.po' based on 'messages.pot'
    Traceback (most recent call last):
      File "/home/georg/env/main/bin/pybabel", line 9, in <module>
        load_entry_point('Babel==1.3', 'console_scripts', 'pybabel')()
      File "/home/georg/env/main/lib/python3.3/site-packages/babel/messages/frontend.py", line 1151, in main
        return CommandLineInterface().run(sys.argv)
      File "/home/georg/env/main/lib/python3.3/site-packages/babel/messages/frontend.py", line 665, in run
        return getattr(self, cmdname)(args[1:])
      File "/home/georg/env/main/lib/python3.3/site-packages/babel/messages/frontend.py", line 1130, in update
        width=options.width)
      File "/home/georg/env/main/lib/python3.3/site-packages/babel/messages/pofile.py", line 444, in write_po
        _write(comment_header + u'\n')
      File "/home/georg/env/main/lib/python3.3/site-packages/babel/messages/pofile.py", line 388, in _write
        fileobj.write(text)
    TypeError: must be str, not bytes
    
    opened by georgthegreat 12
  • Documentation request - using templates

    Documentation request - using templates

    There should be a short introduction in how to use gettext, trans etc in Jinja the jkji2 templates - it's not obvious from the docs that the jinja2 i18n ext is used and that the user does not need to configure this separately.

    opened by danjac 9
  • Fix locale selection in multi-threaded Flask app when force_locale is used

    Fix locale selection in multi-threaded Flask app when force_locale is used

    This fixes issue #117 by setting babel_locale in force_locale context manager instead of replacing locale getter. Babel extension instance is shared across threads (through Flask.extensions) which may cause wrong locale to be selected in request that is processed at the same time in one thread while another thread is using force_locale. Setting locale to request context is thread-safe as Flask doesn't share request contexts between threads. I've added a test case to verify that this fix works, and it failed without changes to force_locale.

    opened by lautat 8
  • Add basic support for locales unkown by Babel

    Add basic support for locales unkown by Babel

    Right now Flask breaks if you request content in a locale that is unknown by Babel even if the translation files actually exist.

    This commit allows translations to be loaded even if the locale is unknown by Babel. Numbers and datetimes ~are returned directly~ use the default locale as a fallback.

    opened by MarcAbonce 8
  • 'Babel' object has no attribute 'translation_directories'

    'Babel' object has no attribute 'translation_directories'

    I am getting a:

    'Babel' object has no attribute 'translation_directories'

    error after updating Flask-Babel from 0.9 to 0.11.1.

    I found a similar reference at https://github.com/airbnb/superset/issues/847 which claims the issue was flask extension compatibility related.

    I have been looking for any sort of documentation that indicates what flask extensions have compatibility with one another, is it just assumed that the minor version (major.minor.build) must match to be compatible?

    Here are my current application versions that are having the issue:

    Babel (2.3.4) Flask (0.11.1) Flask-Babel (0.11.1) Flask-BabelEx (0.9.3) Flask-Compress (1.3.2) Flask-Login (0.4.0) itsdangerous (0.24) Jinja2 (2.8) MarkupSafe (0.23) pytz (2016.7) setuptools (28.8.0) speaklater (1.3) Werkzeug (0.11.11)

    Again, all works with version 0.9 of flask-babel, just trying to understand if compatibility is the root cause or is there a real issue lurking.

    opened by BGraco 8
  • Bug application context since v0.10

    Bug application context since v0.10

    I use flask_script (and flask_migrate) to migrate my sql schema. Since version 0.10 i got this error. Everything works well with 0.9

    File "/usr/local/lib/python2.7/dist-packages/flask_babel/__init__.py", line 215, in get_translations
      babel = current_app.extensions['babel']
    File "/usr/local/lib/python2.7/dist-packages/werkzeug/local.py", line 343, in __getattr__
      return getattr(self._get_current_object(), name)
    File "/usr/local/lib/python2.7/dist-packages/werkzeug/local.py", line 302, in _get_current_object
      return self.__local()
    File "/usr/local/lib/python2.7/dist-packages/flask/globals.py", line 34, in _find_app
      raise RuntimeError('working outside of application context')
    
    opened by johaven 8
  • how to correctly work out of context

    how to correctly work out of context

    Hi, all. I have two subprocesses. one for flask web(called web.py), and one for some background tasks(called task.py). flask-babel works inside the web context, but also the task subprocess will need some translations. so, I import web app into the task.py and use the app.test_request_context in order to make translations work for me. it works at first but then I found task.py will also get the default language only. here is the web.py:

    app.config['BABEL_DEFAULT_LOCALE'] = 'en'
    babel = Babel(app)
    
    @babel.localeselector
    def get_locale():
        return request.accept_languages.best_match(['zh', 'en'])
    

    task.py

    from web import app
    def task():
        try:
            with app.test_request_context() as ctx:
                sio.emit('loading', {'data': _("please wait a moment.")})
    ....
    

    so how can I get the correct locale before I return the translation?? TIA :)

    opened by wiwengweng 7
  • Not extracting strings from some files

    Not extracting strings from some files

    I have a base.html file and navbar.html file. The navbar.html is included in base.html and base extended in other templates. The problem is that babel does not extract strings from navbar.html even though i can see it read it.

    extraction log

    
    

    babel.cfg

    [jinja2: **.htm*]
    encoding = utf-8
    extensions=jinja2.ext.autoescape,jinja2.ext.with_
    

    What could be the problem?

    opened by osleg 7
  • Domains, caching, etc.

    Domains, caching, etc.

    • Implemented localization domain support
    • If babel is not initialized, gettext/format_date/etc won't crash
    • Localization caching - won't reload translations for each and every request
    • Updated tests
    • Updated docs
    opened by mrjoes 7
  • Babel cannot find words in 3's f-Strings ?

    Babel cannot find words in 3's f-Strings ?

    I have some words in 3's f-Strings sql code. such as

    s = f"""
    SELECT * FROM aa
    balabala ...
    case bala...
    {_("abc")}
    WHERE b=1
    """
    

    after I excute the order $ pybabel extract -F babel.cfg -o messages.pot .

    but I cannot find the words 'abc' from file messages.pot

    opened by teddy-lu 0
  • Babel cannot find words in flask_caching blocks

    Babel cannot find words in flask_caching blocks

    If I have html file content like

    <html>
    {% cache 3600, request.url %}
    <tag>{{ _('h1') }}</tag>
    {% endcache %}
    </html>
    

    And run pybabel extract -F babel.cfg -k _l -o translations/messages.pot .

    Flask Babel cannot find new words in {% cache %} block

    opened by serkin 0
  • question about .mo file caching mechanism

    question about .mo file caching mechanism

    Hi there

    I have a question So we all know that .mo will be cached in flask app I just want to know if when we run flask server it caches all .mo files at the beginning? Or is it just when we switch languages then it creates domain objects and caches that .mo file?

    I thought caching all mo files at the beginning would minimize IO time

    opened by 841020 1
  • Add particular callables to Jinja

    Add particular callables to Jinja

    Now with Flask-Babel it is not possible to use gettext particular callables (pgettext, npgettext) in Jinja templates, but install_gettext_callables() supports it. This PR fixes that.

    opened by czepiec 0
  • pypi page links to defunct documentation

    pypi page links to defunct documentation

    Not a problem with the code itself, but it looks like someone needs to update pypi ... it's the first hit on google for the project, and is still linking to https://flask-babel.tkte.ch/ for the documentation, which doesn't exist.

    opened by mpounsett 0
  • docs: fix simple typo, tranlations -> translations

    docs: fix simple typo, tranlations -> translations

    There is a small typo in flask_babel/init.py.

    Should read translations rather than tranlations.

    Semi-automated pull request generated by https://github.com/timgates42/meticulous/blob/master/docs/NOTE.md

    opened by timgates42 0
Releases(v2.0.0)
  • v2.0.0(Aug 27, 2020)

    Starting with version 2, flask-babel drops official support for Python2. Python versions 3.5 through 3.9-beta1 are tested and supported, as well as pypy3.

    • Tests moved from unittest to pytest (#163)
    • Domain and caching support from Flask-BabelEx (#163)
    • Documentation moved from python-hosted to Github Pages.
    • CI moved from Travisci to Github Actions
    • Small documentation improvements.
    • Removed uncessary checks on get_translations() (#127, #126)
    • localeselector and timezoneselector can be changed after creation.
    Source code(tar.gz)
    Source code(zip)
  • v1.0.0(Feb 6, 2020)

    v1.0.0 - 06/02/2020

    Starting with version 1, flask-babel has changed to Semantic Versioning.

    Changed

    • pytz is an explicit dependency. (#14)
    • pytz.gae, used for Google App Engine, is no longer necessary and has been removed. (#153)
    • Fixed a deprecated werkzeug import (#158).
    • Fix issues switching locales in threaded contexts (#125).
    Source code(tar.gz)
    Source code(zip)
Flask RESTful Web services using API to communicate between client and server.

Welcome! Open up two terminals, one for client and for server each Terminal 1 Terminal 2 Now navigate to the CW2_code directory in both like so $ cd C

Sehra Elahi 1 Nov 23, 2021
Lightweight library for providing filtering mechanism for your APIs using SQLAlchemy

sqlalchemy-filters-plus is a light-weight extendable library for filtering queries with sqlalchemy. Install pip install sqlalchemy-fitlers-plus Usage

Karami El Mehdi 38 Oct 05, 2022
Rubik's cube assistant on Flask webapp

webcube Rubik's cube assistant on Flask webapp. This webapp accepts the six faces of your cube and gives you the voice instructions as a response. Req

Yash Indane 56 Nov 22, 2022
Connect is a Python Flask project within the cloud-native ecosystem

Connect is a Python Flask project within the cloud-native ecosystem. Second project of Udacity's Cloud Native Nanodegree program, focusing on documenting and architecting a monolith migration to micr

Lauren Ferreira 3 Feb 28, 2022
Rich implementation for Flask

Flask Rich Implements the Rich programming library with Flask. All features are toggleable, including: Better logging Colorful tracebacks Usage Import

BD103 13 Jun 06, 2022
Flask pre-setup architecture. This can be used in any flask project for a faster and better project code structure.

Flask pre-setup architecture. This can be used in any flask project for a faster and better project code structure. All the required libraries are already installed easily to use in any big project.

Ajay kumar sharma 5 Jun 14, 2022
Pf-flask-rest-com - Flask REST API Common Implementation by Problem Fighter Library

In the name of God, the Most Gracious, the Most Merciful. PF-Flask-Rest-Com Docu

Problem Fighter 3 Jan 15, 2022
OpenTracing instrumentation for the Flask microframework

Flask-OpenTracing This package enables distributed tracing in Flask applications via The OpenTracing Project. Once a production system contends with r

3rd-Party OpenTracing API Contributions 133 Dec 19, 2022
A Flask web application that manages student entries in a SQL database

Student Database App This is a Flask web application that manages student entries in a SQL database. Users can upload a CSV into the SQL database, mak

rebecca 1 Oct 20, 2021
The Snoopy boilerplate in flask framework for development enterprise application.

Snoopy What is snoopy! The "Snoopy" boilerplate in flask framework for development enterprise application. Motivation In my 10 years of development ex

Bekhzod 2 Sep 29, 2022
Python web-app (Flask) to browse Tandoor recipes on the local network

RecipeBook - Tandoor Python web-app (Flask) to browse Tandoor recipes on the local network. Designed for use with E-Ink screens. For a version that wo

5 Oct 02, 2022
SeaSurf is a Flask extension for preventing cross-site request forgery (CSRF).

Flask-SeaSurf SeaSurf is a Flask extension for preventing cross-site request forgery (CSRF). CSRF vulnerabilities have been found in large and popular

Max Countryman 183 Dec 28, 2022
iloveflask is a Python library to collect functions that help a flask developer generate reports, config files and repeat code.

I Love Flask iloveflask is a Python library to collect functions that help a flask developer generate reports, config files and repeat code. Installat

2 Dec 29, 2021
Live Corona statistics and information site with flask.

Flask Live Corona Info Live Corona statistics and information site with flask. Tools Flask Scrapy Matplotlib How to Run Project Download Codes git clo

Mohammad Dori 5 Jul 15, 2022
Are-You-OK is a Flask-based, responsive Web App to monitor whether the Internet Service you care about is still working.

Are-You-OK Are-You-OK is a Flask-based, responsive Web App to monitor whether the Internet Service you care about is still working. Demo-Preview Get S

Tim Qiu 1 Oct 28, 2021
A python package for integrating ripozo with Flask

flask-ripozo This package provides a dispatcher for ripozo so that you can integrate ripozo with Flask. As with all dispatchers it is simply for getti

Vertical Knowledge 14 Dec 03, 2018
Python3🐍 webApp to display your current playing music on OBS Studio.

Spotify Overlay A Overlay to display on Obs Studio or any related video/stream recorder, the current music that is playing on your Spotify. Installati

carlitos 0 Oct 17, 2022
Basic flask system for login, api, and status system

Flask Multi Site With Login This is a basic website login system with an uncomplete api system NOTICE : This is NOT complete and is made to be a bare

MrShoe 0 Feb 02, 2022
A simple demo of using aiogram + async sqlalchemy 1.4+

aiogram-and-sqlalchemy-demo A simple demo of using aiogram + async sqlalchemy 1.4+ Used tech: aiogram SQLAlchemy 1.4+ PostgreSQL as database asyncpg a

Aleksandr 68 Dec 31, 2022
docker-compose uWSGI nginx flask

docker-compose uWSGI nginx flask Note that this was tested on CentOS 7 Usage sudo yum install docker

Abdolkarim Saeedi 3 Sep 11, 2022