[Kimchi-devel] [PATCH V7 5/8] Issue #342: load i18n.html of the plugin

shaohef at linux.vnet.ibm.com shaohef at linux.vnet.ibm.com
Wed Jun 11 10:21:21 UTC 2014


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

Apparently, in plugin code there is no way to insert new entries into
Kimchi ./ui/pages/i18n.json.tmpl, so every plugin should provide its own
i18n.json.tmpl.

each plugin provides a "plugins/plugin-name/ui/pages/i18n.json.tmpl",
and maps it to the URI "plugins/plugin-name/json.html". This is already
supported by the kimchi back-end. What we have to do is just to load
"plugins/plugin-name/i18n.json" in the front-end code.

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  |  4 +++-
 ui/js/src/kimchi.main.js | 13 +++++++++++--
 2 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/ui/js/src/kimchi.api.js b/ui/js/src/kimchi.api.js
index ad89880..0d96d07 100644
--- a/ui/js/src/kimchi.api.js
+++ b/ui/js/src/kimchi.api.js
@@ -71,6 +71,7 @@ var kimchi = {
             type : 'GET',
             resend: true,
             dataType : 'json',
+            async : !sync,
             success : suc,
             error: err
         });
@@ -560,13 +561,14 @@ var kimchi = {
             });
     },
 
-    listPlugins : function(suc, err) {
+    listPlugins : function(suc, err, sync) {
         kimchi.requestJSON({
             url : kimchi.url + 'plugins',
             type : 'GET',
             contentType : 'application/json',
             dataType : 'json',
             resend: true,
+            async : !sync,
             success : suc,
             error : err
         });
diff --git a/ui/js/src/kimchi.main.js b/ui/js/src/kimchi.main.js
index 1e6602c..eb4575a 100644
--- a/ui/js/src/kimchi.main.js
+++ b/ui/js/src/kimchi.main.js
@@ -39,7 +39,7 @@ kimchi.main = function() {
         $(xmlData).find('tab').each(function() {
             var $tab = $(this);
             var titleKey = $tab.find('title').text();
-            var title = i18n[titleKey];
+            var title = i18n[titleKey] ? i18n[titleKey] : titleKey;
             var path = $tab.find('path').text();
             tabs.push({
                 title: title,
@@ -64,6 +64,7 @@ kimchi.main = function() {
 
     var tabConfigUrl = '/config/ui/tabs.xml';
     var pluginConfigUrl = '/plugins/{plugin}/ui/config/tab-ext.xml';
+    var pluginI18nUrl = 'plugins/{plugin}/i18n.json';
     var DEFAULT_HASH;
     var buildTabs = function(callback) {
         var tabs = retrieveTabs(tabConfigUrl);
@@ -72,6 +73,12 @@ kimchi.main = function() {
                 var url = kimchi.substitute(pluginConfigUrl, {
                     plugin: p
                 });
+                var i18nUrl = kimchi.substitute(pluginI18nUrl, {
+                    plugin: p
+                });
+                kimchi.getI18n(function(i18nObj){ $.extend(i18n, i18nObj)},
+                               function(i18nObj){ //i18n is not define by plugin
+                               }, i18nUrl, true);
                 tabs.push.apply(tabs, retrieveTabs(url));
             });
 
@@ -85,7 +92,9 @@ kimchi.main = function() {
             $('#nav-menu').append(genTabs(tabs));
 
             callback && callback();
-        });
+        }, function(data) {
+           kimchi.message.error(data.responseJSON.reason);
+        }, true);
     };
 
     var onLanguageChanged = function(lang) {
-- 
1.9.3




More information about the Kimchi-devel mailing list