diff --git a/flask_babel/__init__.py b/flask_babel/__init__.py index a3436c0..a76bf7c 100644 --- a/flask_babel/__init__.py +++ b/flask_babel/__init__.py @@ -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 diff --git a/tests/test_gettext.py b/tests/test_gettext.py index 7d1843c..6a57832 100644 --- a/tests/test_gettext.py +++ b/tests/test_gettext.py @@ -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.