Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix output of --list-locales to not use bytes reprs #845

Merged
merged 1 commit into from Apr 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 1 addition & 5 deletions babel/messages/frontend.py
Expand Up @@ -22,7 +22,6 @@
from configparser import RawConfigParser
from datetime import datetime
from io import StringIO
from locale import getpreferredencoding

from babel import __version__ as VERSION
from babel import Locale, localedata
Expand Down Expand Up @@ -906,10 +905,7 @@ def run(self, argv=None):
format = u'%%-%ds %%s' % (longest + 1)
for identifier in identifiers:
locale = Locale.parse(identifier)
output = format % (identifier, locale.english_name)
print(output.encode(sys.stdout.encoding or
getpreferredencoding() or
'ascii', 'replace'))
print(format % (identifier, locale.english_name))
return 0

if not args:
Expand Down
11 changes: 11 additions & 0 deletions tests/messages/test_frontend.py
Expand Up @@ -756,6 +756,17 @@ def test_usage(self):
pybabel: error: no valid command or option passed. try the -h/--help option for more information.
""", sys.stderr.getvalue().lower())

def test_list_locales(self):
"""
Test the command with the --list-locales arg.
"""
result = self.cli.run(sys.argv + ['--list-locales'])
assert not result
output = sys.stdout.getvalue()
assert 'fr_CH' in output
assert 'French (Switzerland)' in output
assert "\nb'" not in output # No bytes repr markers in output

def _run_init_catalog(self):
i18n_dir = os.path.join(data_dir, 'project', 'i18n')
pot_path = os.path.join(data_dir, 'project', 'i18n', 'messages.pot')
Expand Down