Skip to content

Commit

Permalink
Merge pull request #219 from jpvanhal/fix-list-translations-duplicate…
Browse files Browse the repository at this point in the history
…-default-locale

Fix list_translations() not to return default locale twice
  • Loading branch information
TkTech authored Apr 3, 2023
2 parents 7510e9c + dde128c commit bde0153
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
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

0 comments on commit bde0153

Please sign in to comment.