Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix list_translations() not to return default locale twice
`list_translations()` was returning the default locale twice if there
was a translation file for the default locale.
  • Loading branch information
jpvanhal committed Feb 15, 2023
1 parent a57e3ee commit dde128c
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
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
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 dde128c

Please sign in to comment.