mirror of
https://github.com/YunoHost/moulinette.git
synced 2024-09-03 20:06:31 +02:00
[fix] Fix encoding issue due to Python 2 in i18n and cli prompting
This commit is contained in:
parent
9e4b266a5a
commit
1ab91440f1
2 changed files with 12 additions and 6 deletions
|
@ -191,7 +191,7 @@ class Translator(object):
|
|||
logging.warning("unknown key '%s' for locale '%s'" %
|
||||
(key, self.default_locale))
|
||||
return key
|
||||
return value.encode('utf-8')
|
||||
return value
|
||||
|
||||
def _load_translations(self, locale, overwrite=False):
|
||||
"""Load translations for a locale
|
||||
|
@ -212,7 +212,7 @@ class Translator(object):
|
|||
|
||||
try:
|
||||
with open('%s/%s.json' % (self.locale_dir, locale), 'r') as f:
|
||||
j = json.load(f)
|
||||
j = json.load(f, 'utf-8')
|
||||
except IOError:
|
||||
return False
|
||||
else:
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
# TODO: Switch to python3!
|
||||
from __future__ import print_function
|
||||
|
||||
import os
|
||||
import errno
|
||||
import getpass
|
||||
|
@ -32,7 +35,7 @@ def colorize(astr, color):
|
|||
|
||||
"""
|
||||
if os.isatty(1):
|
||||
return '\033[{:d}m\033[1m{:s}\033[m'.format(colors_codes[color], astr)
|
||||
return u'\033[{:d}m\033[1m{:s}\033[m'.format(colors_codes[color], astr)
|
||||
else:
|
||||
return astr
|
||||
|
||||
|
@ -226,10 +229,13 @@ class Interface(BaseInterface):
|
|||
|
||||
"""
|
||||
if is_password:
|
||||
prompt = lambda m: getpass.getpass(colorize(m18n.g('colon') % m,
|
||||
'blue'))
|
||||
def prompt(m):
|
||||
print(colorize(m18n.g('colon') % m, 'blue'), end='')
|
||||
return getpass.getpass()
|
||||
else:
|
||||
prompt = lambda m: raw_input(colorize(m18n.g('colon') % m, 'blue'))
|
||||
def prompt(m):
|
||||
print(colorize(m18n.g('colon') % m, 'blue'), end='')
|
||||
return raw_input()
|
||||
value = prompt(message)
|
||||
|
||||
if confirm:
|
||||
|
|
Loading…
Add table
Reference in a new issue