URL: https://github.com/freeipa/freeipa/pull/1326 Author: slaykovsky Title: #1326: [WIP] Fixing translation problems Action: opened
PR body: """ Hello guys! So I'm having some progress with this weird translation related bug and I already achieved the following behaviour: ``` # LANG=de_DE.UTF-8 ipa user-find admin -------------- 1 user matched -------------- Anmeldename: admin Nachname: Administrator Home-Verzeichnis: /home/admin Anmeldeshell: /bin/bash Principal alias: ad...@dom-023.abc.idm.lab.eng.brq.redhat.com UID: 1026200000 Gruppen-ID: 1026200000 Konto ist deaktiviert: False ------------------------------------- Anzahl der zurückgegebenen Einträge 1 ------------------------------------- # LANG=zh_CN.UTF-8 ipa user-find admin -------------- 1 user matched -------------- 用户登录名: admin 姓: Administrator 主目录: /home/admin 登录shell: /bin/bash 主体别名: ad...@dom-023.abc.idm.lab.eng.brq.redhat.com UID: 1026200000 GID: 1026200000 禁用账户: False -------- 返回的条目数 1 -------- # LANG=en_US.UTF-8 ipa user-find admin -------------- 1 user matched -------------- User login: admin Last name: Administrator Home directory: /home/admin Login shell: /bin/bash Principal alias: ad...@dom-023.abc.idm.lab.eng.brq.redhat.com UID: 1026200000 GID: 1026200000 Account disabled: False ---------------------------- Number of entries returned 1 ---------------------------- ``` As you can see now I don't need as a user to clean `~/.cache/ipa` to get the information in my native locale. But, there is this summary (in this case it's `1 user matched`) which is getting generated on the server and I'm kind of struggling with it now as I removed this `LANG` changing piece of code from rpcserver. Any help, review and comment are needed and very appreciated. :) pagure: https://pagure.io/freeipa/issue/7238 """ To pull the PR as Git branch: git remote add ghfreeipa https://github.com/freeipa/freeipa git fetch ghfreeipa pull/1326/head:pr1326 git checkout pr1326
From 6590939f9b2be25240f4b4708a9bc44b4b967c10 Mon Sep 17 00:00:00 2001 From: Aleksei Slaikovskii <aslai...@redhat.com> Date: Thu, 23 Nov 2017 13:34:59 +0100 Subject: [PATCH] [WIP] Fixing translation problems Any help is needed. :) pagure: https://pagure.io/freeipa/issue/7238 --- ipalib/cli.py | 5 ++++- ipalib/frontend.py | 4 ++-- ipaserver/rpcserver.py | 11 ----------- 3 files changed, 6 insertions(+), 14 deletions(-) diff --git a/ipalib/cli.py b/ipalib/cli.py index 6abc348d94..819b4b6826 100644 --- a/ipalib/cli.py +++ b/ipalib/cli.py @@ -386,7 +386,7 @@ def print_entry(self, entry, order=None, labels=None, flags=None, print_all=True for key in order: if key not in entry: continue - label = labels.get(key, key) + label = unicode(_(labels.get(key, key))) flag = flags.get(key, []) value = entry[key] if ('suppress_empty' in flag and @@ -437,6 +437,9 @@ def print_dashed(self, string, above=True, below=True, indent=0, dash='-'): ------------------ Only dashed above. """ + if not isinstance(string, six.string_types): + string = unicode(string) + assert isinstance(dash, six.string_types) assert len(dash) == 1 dashes = dash * len(string) diff --git a/ipalib/frontend.py b/ipalib/frontend.py index 3a05bb6eb8..bc3d39ae75 100644 --- a/ipalib/frontend.py +++ b/ipalib/frontend.py @@ -1051,7 +1051,7 @@ def output_for_cli(self, textui, output, *args, **options): if options.get('raw', False): labels = None else: - labels = dict((p.name, unicode(p.label)) for p in self.output_params()) + labels = dict((p.name, p.label) for p in self.output_params()) flags = dict((p.name, p.flags) for p in self.output_params()) for o in self.output: @@ -1089,7 +1089,7 @@ def output_for_cli(self, textui, output, *args, **options): # success or failure. Ignore these. pass elif isinstance(result, int): - textui.print_count(result, '%s %%d' % unicode(self.output[o].doc)) + textui.print_count(result, '%s %%d' % unicode(_(self.output[o].doc))) return rv diff --git a/ipaserver/rpcserver.py b/ipaserver/rpcserver.py index 5cbacf406d..6f150d0020 100644 --- a/ipaserver/rpcserver.py +++ b/ipaserver/rpcserver.py @@ -346,15 +346,6 @@ def wsgi_execute(self, environ): if not environ['HTTP_REFERER'].startswith('https://%s/ipa' % self.api.env.host) and not self.env.in_tree: return self.marshal(result, RefererError(referer=environ['HTTP_REFERER']), _id) try: - if ('HTTP_ACCEPT_LANGUAGE' in environ): - lang_reg_w_q = environ['HTTP_ACCEPT_LANGUAGE'].split(',')[0] - lang_reg = lang_reg_w_q.split(';')[0] - lang_ = lang_reg.split('-')[0] - if '-' in lang_reg: - reg = lang_reg.split('-')[1].upper() - else: - reg = lang_.upper() - os.environ['LANG'] = '%s_%s' % (lang_, reg) if ( environ.get('CONTENT_TYPE', '').startswith(self.content_type) and environ['REQUEST_METHOD'] == 'POST' @@ -378,8 +369,6 @@ def wsgi_execute(self, environ): 'non-public: %s: %s', e.__class__.__name__, str(e) ) error = InternalError() - finally: - os.environ['LANG'] = lang principal = getattr(context, 'principal', 'UNKNOWN') if command is not None:
_______________________________________________ FreeIPA-devel mailing list -- freeipa-devel@lists.fedorahosted.org To unsubscribe send an email to freeipa-devel-le...@lists.fedorahosted.org