Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'Babel' object has no attribute 'translation_directories' #111

Closed
BGraco opened this issue Nov 22, 2016 · 8 comments
Closed

'Babel' object has no attribute 'translation_directories' #111

BGraco opened this issue Nov 22, 2016 · 8 comments

Comments

@BGraco
Copy link

BGraco commented Nov 22, 2016

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.

@jb-l
Copy link

jb-l commented Aug 23, 2017

Just in case someone find this useful: I had the same problem, but i tracked it down to an incorrect import of gettext (between flask-babel and flask-babelex).
I cannot be sure for @BGraco case but this error might not be linked to Flask-Babel.

To reproduce the error :

from flask import Flask
from flask_babelex import Babel
from flask_babel import gettext# <- This is incorrect, it should be imported from flask_babelex

app = Flask(__name__)
babel = Babel(app)

@app.route('/')
def hello_world():
    return gettext("Hello World")

app.run()

@BGraco
Copy link
Author

BGraco commented Aug 23, 2017

@jb-l Thank you so much for taking the time to post!
Just tried your fix, and it worked.

@BGraco BGraco closed this as completed Aug 23, 2017
@Chamaeleon-
Copy link

I had just a similar problem but with babel.load_locale:
AttributeError: 'Babel' object has no attribute 'load_locale'
Your fix worked for me too, maybe the Flask-Babel Documentation should be updated?

@jb-l
Copy link

jb-l commented Aug 24, 2017

My comment is a bit misleading : I don't think it is a Flask-Babel problem but it is more a problem for Flask-Babelex or on documentation of packages using Flask-Babelex.

These problems appear when you start mixing Flask-Babel and Flask-Babelex (it seems that today Flask-Babelex is not API compatible with Flask-Babel) . Actually I started with your problem @Chamaeleon- (it took me some time to notice that Flask-Security relies on Flask-Babelex).

@Chamaeleon-
Copy link

@jb-l uh, Flask-Security uses Babelex? I wonderd why i got problems with mixing up Babelex and Babel, because i only use Babel in my code.
But indeed, I use also Flask-Security, but doesn't expect it to be the reason of my Flask-Babel problems...

@tobias533
Copy link

Using Flask-Security, I had the same error:

"AttributeError: 'Babel' object has no attribute 'load_locale'"

I found out that I still used in one handwritten library

from flask_babel import gettext

instead of

from flask_babelex import gettext

Now, I corrected this issue and it works fine.

@LaundroMat
Copy link

LaundroMat commented Mar 27, 2019

I have the exact same problem, but importing from flask_babelex didn't solve it. Does anyone have other suggestions?

Update: scratch that. I forgot about Babel itself. This solves it for me

from flask_babelex import Babel, gettext, lazy_gettext

@masete
Copy link

masete commented Mar 14, 2021

did you first uninstall babel or do you have babel and babelex installed. This could still cause issues just use bablex as recommended in the docks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants