Skip to content

Commit

Permalink
Always include the default locale in list_translations, even if it do…
Browse files Browse the repository at this point in the history
…es not exist. (#75)
  • Loading branch information
TkTech committed Jan 15, 2023
1 parent 2a99489 commit f1f6696
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ Major version bump as this version removes support for Python 3.5 and 3.6.
- Dropped support for end-of-life Python 3.5 and 3.6, added tests for 3.10 and 3.11.
- Fixes to documentation to address outdated links and settings (#204, 201)
- Jinja version 3 or greater is now required (released 2021)
- Removed Babel._date_formats, use the public Babel.date_formats instead.
- Removed Babel._date_formats, use the public Babel.date_formats instead.
- list_translations() always returns the default locale, even if it does not exist. (#75)
10 changes: 6 additions & 4 deletions flask_babel/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,11 @@ def list_translations(self):
"""Returns a list of all the locales translations exist for. The list
returned will be filled with actual locale objects and not just strings.
.. note::
The default locale will always be returned, even if no translation
files exist for it.
.. versionadded:: 0.6
"""
result = []
Expand All @@ -153,10 +158,7 @@ def list_translations(self):
if any(x.endswith('.mo') for x in os.listdir(locale_dir)):
result.append(Locale.parse(folder))

# If no other translations are found, add the default locale
if not result:
result.append(self.default_locale)

result.append(self.default_locale)
return result

@property
Expand Down

0 comments on commit f1f6696

Please sign in to comment.