Skip to content

Commit dde128c

Browse files
committed
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.
1 parent a57e3ee commit dde128c

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

flask_babel/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,8 @@ def list_translations(self):
197197
if any(x.endswith('.mo') for x in os.listdir(locale_dir)):
198198
result.append(Locale.parse(folder))
199199

200-
result.append(self.default_locale)
200+
if self.default_locale not in result:
201+
result.append(self.default_locale)
201202
return result
202203

203204
@property

tests/test_gettext.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,16 @@ def test_list_translations():
9696
assert str(translations[1]) == 'de_DE'
9797

9898

99+
def test_list_translations_default_locale_exists():
100+
app = flask.Flask(__name__)
101+
b = babel.Babel(app, default_locale='de')
102+
103+
with app.app_context():
104+
translations = b.list_translations()
105+
assert len(translations) == 1
106+
assert str(translations[0]) == 'de'
107+
108+
99109
def test_no_formatting():
100110
"""
101111
Ensure we don't format strings unless a variable is passed.

0 commit comments

Comments
 (0)