[Kimchi-devel] [PATCH] [Wok] Bug fix #192: Check the specific domain file exists on mo directory
Daniel Henrique Barboza
dhbarboza82 at gmail.com
Tue Apr 4 18:49:11 UTC 2017
Reviewed-by: Daniel Barboza <danielhb at linux.vnet.ibm.com>
On 04/04/2017 12:58 PM, Aline Manera wrote:
> 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 <alinefm at linux.vnet.ibm.com>
> ---
> 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 = app.root.domain
> paths = app.root.paths
> - lang = validate_language(get_lang())
> + lang = validate_language(get_lang(), domain)
>
> try:
> translation = 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
> -
>
> from wok import config as config
> from wok.config import paths
> @@ -60,15 +59,10 @@ def get_accept_language():
> return langs
>
>
> -def get_support_languages():
> - mopath = "%s/*" % paths.mo_dir
> - return [path.rsplit('/', 1)[1] for path in iglob(mopath)]
> -
> -
> -def validate_language(langs):
> - supportLangs = get_support_languages()
> +def validate_language(langs, domain):
> for lang in langs:
> - if lang in supportLangs:
> + filepath = os.path.join(paths.mo_dir, lang, domain + '.mo')
> + if os.path.exists(filepath):
> return lang
> return "en_US"
>
> @@ -96,11 +90,12 @@ def can_accept_html():
>
> def render_cheetah_file(resource, data):
> paths = cherrypy.request.app.root.paths
> + domain = cherrypy.request.app.root.domain
> filename = paths.get_template_path(resource)
> try:
> params = {}
> - lang = validate_language(get_lang())
> - gettext_conf = {'domain': cherrypy.request.app.root.domain,
> + lang = validate_language(get_lang(), domain)
> + gettext_conf = {'domain': domain,
> 'localedir': paths.mo_dir,
> 'lang': [lang]}
> params['lang'] = gettext_conf
More information about the Kimchi-devel
mailing list