From nobody Sat Apr 20 08:15:55 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of ovirt.org designates 66.187.230.42 as permitted sender) client-ip=66.187.230.42; envelope-from=kimchi-devel-bounces@ovirt.org; helo=lists.ovirt.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of ovirt.org designates 66.187.230.42 as permitted sender) smtp.mailfrom=kimchi-devel-bounces@ovirt.org; Return-Path: Received: from lists.ovirt.org (lists.phx.ovirt.org [66.187.230.42]) by mx.zohomail.com with SMTPS id 1491321583374971.922963093232; Tue, 4 Apr 2017 08:59:43 -0700 (PDT) Received: from lists.phx.ovirt.org (localhost [127.0.0.1]) by lists.ovirt.org (Postfix) with ESMTP id 32BCD820528; Tue, 4 Apr 2017 15:59:42 +0000 (UTC) Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by lists.ovirt.org (Postfix) with ESMTPS id B6F06820520 for ; Tue, 4 Apr 2017 15:59:13 +0000 (UTC) Received: from pps.filterd (m0098409.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.20/8.16.0.20) with SMTP id v34Frt28055132 for ; Tue, 4 Apr 2017 11:59:13 -0400 Received: from e24smtp04.br.ibm.com (e24smtp04.br.ibm.com [32.104.18.25]) by mx0a-001b2d01.pphosted.com with ESMTP id 29m51mxtpn-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Tue, 04 Apr 2017 11:59:12 -0400 Received: from localhost by e24smtp04.br.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 4 Apr 2017 12:59:09 -0300 Received: from d24relay04.br.ibm.com (9.18.232.146) by e24smtp04.br.ibm.com (10.172.0.140) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 4 Apr 2017 12:59:06 -0300 Received: from d24av01.br.ibm.com (d24av01.br.ibm.com [9.8.31.91]) by d24relay04.br.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v34Fx6VK35193070 for ; Tue, 4 Apr 2017 12:59:06 -0300 Received: from d24av01.br.ibm.com (localhost [127.0.0.1]) by d24av01.br.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id v34Fx6sK019564 for ; Tue, 4 Apr 2017 12:59:06 -0300 Received: from alinefm-TP440.br.ibm.com (alinefm-TP440.br.ibm.com [9.18.239.40]) by d24av01.br.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id v34Fx629019408 for ; Tue, 4 Apr 2017 12:59:06 -0300 X-Original-To: kimchi-devel@ovirt.org From: Aline Manera To: Kimchi Devel Date: Tue, 4 Apr 2017 12:58:50 -0300 X-Mailer: git-send-email 2.9.3 X-TM-AS-MML: disable x-cbid: 17040415-0028-0000-0000-000001A79A8F X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17040415-0029-0000-0000-000014A79E13 Message-Id: <20170404155850.22332-1-alinefm@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-04-04_12:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=0 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1702020001 definitions=main-1704040138 Subject: [Kimchi-devel] [PATCH] [Wok] Bug fix #192: Check the specific domain file exists on mo directory X-BeenThere: kimchi-devel@ovirt.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: kimchi-devel-bounces@ovirt.org Errors-To: kimchi-devel-bounces@ovirt.org X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Before it was checking the mo directory exists which may fail if it exists but does not have a specific domain file. Signed-off-by: Aline Manera Reviewed-by: Daniel Barboza --- src/wok/message.py | 2 +- src/wok/template.py | 19 +++++++------------ 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/src/wok/message.py b/src/wok/message.py index 56cd022..a335881 100644 --- a/src/wok/message.py +++ b/src/wok/message.py @@ -73,7 +73,7 @@ class WokMessage(object): # do translation domain =3D app.root.domain paths =3D app.root.paths - lang =3D validate_language(get_lang()) + lang =3D validate_language(get_lang(), domain) =20 try: translation =3D gettext.translation(domain, paths.mo_dir, = [lang]) diff --git a/src/wok/template.py b/src/wok/template.py index 43a34db..b033394 100644 --- a/src/wok/template.py +++ b/src/wok/template.py @@ -22,10 +22,9 @@ import cherrypy import errno import json +import os import time from Cheetah.Template import Template -from glob import iglob - =20 from wok import config as config from wok.config import paths @@ -60,15 +59,10 @@ def get_accept_language(): return langs =20 =20 -def get_support_languages(): - mopath =3D "%s/*" % paths.mo_dir - return [path.rsplit('/', 1)[1] for path in iglob(mopath)] - - -def validate_language(langs): - supportLangs =3D get_support_languages() +def validate_language(langs, domain): for lang in langs: - if lang in supportLangs: + filepath =3D os.path.join(paths.mo_dir, lang, domain + '.mo') + if os.path.exists(filepath): return lang return "en_US" =20 @@ -96,11 +90,12 @@ def can_accept_html(): =20 def render_cheetah_file(resource, data): paths =3D cherrypy.request.app.root.paths + domain =3D cherrypy.request.app.root.domain filename =3D paths.get_template_path(resource) try: params =3D {} - lang =3D validate_language(get_lang()) - gettext_conf =3D {'domain': cherrypy.request.app.root.domain, + lang =3D validate_language(get_lang(), domain) + gettext_conf =3D {'domain': domain, 'localedir': paths.mo_dir, 'lang': [lang]} params['lang'] =3D gettext_conf --=20 2.9.3 _______________________________________________ Kimchi-devel mailing list Kimchi-devel@ovirt.org http://lists.ovirt.org/mailman/listinfo/kimchi-devel