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'" %
|
logging.warning("unknown key '%s' for locale '%s'" %
|
||||||
(key, self.default_locale))
|
(key, self.default_locale))
|
||||||
return key
|
return key
|
||||||
return value.encode('utf-8')
|
return value
|
||||||
|
|
||||||
def _load_translations(self, locale, overwrite=False):
|
def _load_translations(self, locale, overwrite=False):
|
||||||
"""Load translations for a locale
|
"""Load translations for a locale
|
||||||
|
@ -212,7 +212,7 @@ class Translator(object):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with open('%s/%s.json' % (self.locale_dir, locale), 'r') as f:
|
with open('%s/%s.json' % (self.locale_dir, locale), 'r') as f:
|
||||||
j = json.load(f)
|
j = json.load(f, 'utf-8')
|
||||||
except IOError:
|
except IOError:
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
# TODO: Switch to python3!
|
||||||
|
from __future__ import print_function
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import errno
|
import errno
|
||||||
import getpass
|
import getpass
|
||||||
|
@ -32,7 +35,7 @@ def colorize(astr, color):
|
||||||
|
|
||||||
"""
|
"""
|
||||||
if os.isatty(1):
|
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:
|
else:
|
||||||
return astr
|
return astr
|
||||||
|
|
||||||
|
@ -226,10 +229,13 @@ class Interface(BaseInterface):
|
||||||
|
|
||||||
"""
|
"""
|
||||||
if is_password:
|
if is_password:
|
||||||
prompt = lambda m: getpass.getpass(colorize(m18n.g('colon') % m,
|
def prompt(m):
|
||||||
'blue'))
|
print(colorize(m18n.g('colon') % m, 'blue'), end='')
|
||||||
|
return getpass.getpass()
|
||||||
else:
|
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)
|
value = prompt(message)
|
||||||
|
|
||||||
if confirm:
|
if confirm:
|
||||||
|
|
Loading…
Add table
Reference in a new issue