[Kimchi-devel] [PATCH V3 4/7] Add JS API for fetching i18n JSON

shaohef at linux.vnet.ibm.com shaohef at linux.vnet.ibm.com
Wed May 21 08:54:39 UTC 2014


From: ShaoHe Feng <shaohef at linux.vnet.ibm.com>

Create an API for fetching the i18n JSON.
Use the API to load the kimchi UI strings.

API will need to be simplified after convincing CherryPy to respond to the reque
st for JSON.

Signed-off-by: Adam King <rak at linux.vnet.ibm.com>
Signed-off-by: ShaoHe Feng <shaohef at linux.vnet.ibm.com>
---
 ui/js/src/kimchi.api.js  | 14 ++++++++++++++
 ui/js/src/kimchi.main.js | 11 ++++++++---
 2 files changed, 22 insertions(+), 3 deletions(-)

diff --git a/ui/js/src/kimchi.api.js b/ui/js/src/kimchi.api.js
index 7d85fdf..19557c6 100644
--- a/ui/js/src/kimchi.api.js
+++ b/ui/js/src/kimchi.api.js
@@ -63,6 +63,20 @@ var kimchi = {
     },
 
     /**
+     * Get the i18 strings.
+     */
+    getI18n: function(suc, err, url, sync) {
+        kimchi.requestJSON({
+            url : url ? url : kimchi.url + 'i18n.json',
+            type : 'GET',
+            resend: true,
+            dataType : 'json',
+            success : suc,
+            error: err
+        });
+    },
+
+    /**
      * Get the host static information.
      */
     getHost: function(suc, err) {
diff --git a/ui/js/src/kimchi.main.js b/ui/js/src/kimchi.main.js
index 86fed5b..3b130d0 100644
--- a/ui/js/src/kimchi.main.js
+++ b/ui/js/src/kimchi.main.js
@@ -247,9 +247,14 @@ kimchi.main = function() {
     };
 
     // Load i18n translation strings first and then render the page.
-    $('#main').load('i18n.html', function() {
-        buildTabs(initUI);
-    });
+    kimchi.getI18n(
+        function(i18nStrings){ //success
+            i18n=i18nStrings;
+            buildTabs(initUI);
+            },
+        function(data){ //error
+            kimchi.message.error(data.responseJSON.reason);
+            });
 };
 
 kimchi.getHelp = function(e) {
-- 
1.9.0




More information about the Kimchi-devel mailing list