[imp] used the user language
[odoo/odoo.git] / addons / base / controllers / main.py
index 4f6b3ea..d4d4205 100644 (file)
@@ -18,6 +18,7 @@ import openerpweb
 import openerpweb.ast
 import openerpweb.nonliterals
 
+from babel.messages.pofile import read_po
 
 # Should move to openerpweb.Xml2Json
 class Xml2Json:
@@ -156,6 +157,26 @@ class WebClient(openerpweb.Controller):
             'css': css
         }
         return r
+    
+    @openerpweb.jsonrequest
+    def translations(self, req, mods, lang):
+        transs = {}
+        for addon_name in mods:
+            transl = {"messages":[]}
+            transs[addon_name] = transl
+            f_name = os.path.join(openerpweb.path_addons, addon_name, "po", lang + ".po")
+            if not os.path.exists(f_name):
+                continue
+            try:
+                with open(f_name) as t_file:
+                    po = read_po(t_file)
+            except:
+                continue
+            for x in po:
+                if x.id:
+                    transl["messages"].append({'id': x.id, 'string': x.string})
+        return {"modules": transs}
+    
 
 class Database(openerpweb.Controller):
     _cp_path = "/base/database"
@@ -251,10 +272,12 @@ class Session(openerpweb.Controller):
     @openerpweb.jsonrequest
     def login(self, req, db, login, password):
         req.session.login(db, login, password)
+        ctx = req.session.get_context()
 
         return {
             "session_id": req.session_id,
             "uid": req.session._uid,
+            "context": ctx
         }
 
     @openerpweb.jsonrequest
@@ -772,8 +795,8 @@ class View(openerpweb.Controller):
         """ Parses an arbitrary string containing a domain, transforms it
         to either a literal domain or a :class:`openerpweb.nonliterals.Domain`
 
-        :param domain: the domain to parse, if the domain is not a string it is assumed to
-        be a literal domain and is returned as-is
+        :param domain: the domain to parse, if the domain is not a string it
+                       is assumed to be a literal domain and is returned as-is
         :param session: Current OpenERP session
         :type session: openerpweb.openerpweb.OpenERPSession
         """
@@ -789,8 +812,8 @@ class View(openerpweb.Controller):
         """ Parses an arbitrary string containing a context, transforms it
         to either a literal context or a :class:`openerpweb.nonliterals.Context`
 
-        :param context: the context to parse, if the context is not a string it is assumed to
-        be a literal domain and is returned as-is
+        :param context: the context to parse, if the context is not a string it
+               is assumed to be a literal domain and is returned as-is
         :param session: Current OpenERP session
         :type session: openerpweb.openerpweb.OpenERPSession
         """