[fix] Add i18n in yunohost binaries and update them

This commit is contained in:
Jérôme Lebleu 2014-05-16 12:29:41 +02:00
parent 60c6150877
commit b501e186be
4 changed files with 25 additions and 18 deletions

View file

@ -28,19 +28,23 @@ if __name__ == '__main__':
use_cache = False
sys.argv.remove('--no-cache')
try:
args = list(sys.argv)
args.pop(0)
# Check that YunoHost is installed
if not os.path.isfile('/etc/yunohost/installed') \
and (len(args) < 2 or args[1] != 'tools' or args[2] != 'postinstall'):
raise YunoHostError(17, _("YunoHost is not correctly installed, please execute 'yunohost tools postinstall'"))
if not os.path.isfile('/etc/yunohost/installed') and \
(len(args) < 2 or args[1] != 'tools' or args[2] != 'postinstall'):
from moulinette.interfaces.cli import colorize, get_locale
# Init i18n
m18n.load_namespace('yunohost')
m18n.set_locale(get_locale())
# Print error and exit
print('%s %s' % (colorize(m18n.g('error'), 'red'),
m18n.n('yunohost_not_installed')))
sys.exit(1)
# Execute the action
ret = cli(['yunohost'], args, use_cache)
except YunoHostError as e:
# TODO: Remove this and associated import when yunohost package has been revisited
print(colorize(_("Error: "), 'red') + e.message)
sys.exit(e.code)
sys.exit(ret)

View file

@ -47,6 +47,6 @@ if __name__ == '__main__':
{('GET', '/installed'): is_installed}, use_cache)
except MoulinetteError as e:
from moulinette.interfaces.cli import colorize
print(_('%s: %s' % (colorize(_('Error'), 'red'), e.strerror)))
print('%s %s' % (colorize(m18n.g('error'), 'red'), e.strerror))
sys.exit(e.errno)
sys.exit(0)

View file

@ -1,5 +1,6 @@
{
"yunohost" : "YunoHost",
"yunohost_not_installed" : "YunoHost is not or not correctly installed. Please execute 'yunohost tools postinstall'.",
"upgrade_complete" : "Upgrade complete",
"installation_complete" : "Installation complete",

View file

@ -4,6 +4,7 @@ import os
import errno
import getpass
import argparse
import locale
from moulinette.core import MoulinetteError
from moulinette.interfaces import (BaseActionsMapParser, BaseInterface)
@ -63,6 +64,10 @@ def pretty_print_dict(d, depth=0):
v = str(v)
print((" ") * depth + "%s: %s" % (str(k), v))
def get_locale():
"""Return current user locale"""
lang = locale.getdefaultlocale()[0]
return lang[:2]
# CLI Classes Implementation -------------------------------------------
@ -157,11 +162,8 @@ class Interface(BaseInterface):
"""
def __init__(self, actionsmap):
import locale
# Set user locale
lang = locale.getdefaultlocale()[0]
m18n.set_locale(lang[:2])
m18n.set_locale(get_locale())
# Connect signals to handlers
msignals.set_handler('authenticate', self._do_authenticate)