[Kimchi-devel] [PATCH] [Wok] Bug fix #192: Check the specific domain file exists on mo directory

Aline Manera posted 1 patch 87 weeks ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/kimchi tags/patchew/20170404155850.22332-1-alinefm@linux.vnet.ibm.com
src/wok/message.py  |  2 +-
src/wok/template.py | 19 +++++++------------
2 files changed, 8 insertions(+), 13 deletions(-)

[Kimchi-devel] [PATCH] [Wok] Bug fix #192: Check the specific domain file exists on mo directory

Posted by Aline Manera 87 weeks ago
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@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
-- 
2.9.3

_______________________________________________
Kimchi-devel mailing list
Kimchi-devel@ovirt.org
http://lists.ovirt.org/mailman/listinfo/kimchi-devel

Re: [Kimchi-devel] [PATCH] [Wok] Bug fix #192: Check the specific domain file exists on mo directory

Posted by Daniel Henrique Barboza 87 weeks ago
Reviewed-by: Daniel Barboza <danielhb@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@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

_______________________________________________
Kimchi-devel mailing list
Kimchi-devel@ovirt.org
http://lists.ovirt.org/mailman/listinfo/kimchi-devel

Re: [Kimchi-devel] [PATCH] [Wok] Bug fix #192: Check the specific domain file exists on mo directory

Posted by Aline Manera 87 weeks ago
Applied. Thanks.

Regards,

Aline Manera

_______________________________________________
Kimchi-devel mailing list
Kimchi-devel@ovirt.org
http://lists.ovirt.org/mailman/listinfo/kimchi-devel