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

Fix list_translations() not to return default locale twice #219

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion flask_babel/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,8 @@ def list_translations(self):
if any(x.endswith('.mo') for x in os.listdir(locale_dir)):
result.append(Locale.parse(folder))

result.append(self.default_locale)
if self.default_locale not in result:
result.append(self.default_locale)
return result

@property
Expand Down
10 changes: 10 additions & 0 deletions tests/test_gettext.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,16 @@ def test_list_translations():
assert str(translations[1]) == 'de_DE'


def test_list_translations_default_locale_exists():
app = flask.Flask(__name__)
b = babel.Babel(app, default_locale='de')

with app.app_context():
translations = b.list_translations()
assert len(translations) == 1
assert str(translations[0]) == 'de'


def test_no_formatting():
"""
Ensure we don't format strings unless a variable is passed.
Expand Down