[PATCH] Issue #342: load i18n.html of the plugin

From: ShaoHe Feng <shaohef@linux.vnet.ibm.com> Apparently, in plugin code there is no way to insert new entries into Kimchi ./ui/pages/i18n.html.tmpl, so every plugin should provide its own i18n.html.tmpl. each plugin provides a "plugins/plugin-name/ui/pages/i18n.html.tmpl", and maps it to the URI "plugins/plugin-name/i18n.html". This is already supported by the kimchi back-end. What we have to do is just to load "plugins/plugin-name/i18n.html" in the front-end code. Signed-off-by: ShaoHe Feng <shaohef@linux.vnet.ibm.com> --- ui/js/src/kimchi.api.js | 3 ++- ui/js/src/kimchi.main.js | 19 ++++++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/ui/js/src/kimchi.api.js b/ui/js/src/kimchi.api.js index 7d85fdf..d4d92d8 100644 --- a/ui/js/src/kimchi.api.js +++ b/ui/js/src/kimchi.api.js @@ -558,13 +558,14 @@ var kimchi = { }); }, - listPlugins : function(suc, err) { + listPlugins : function(suc, err, async) { kimchi.requestJSON({ url : kimchi.url + 'plugins', type : 'GET', contentType : 'application/json', dataType : 'json', resend: true, + async: async ? async : true, success : suc, error : err }); diff --git a/ui/js/src/kimchi.main.js b/ui/js/src/kimchi.main.js index 86fed5b..82778cc 100644 --- a/ui/js/src/kimchi.main.js +++ b/ui/js/src/kimchi.main.js @@ -62,8 +62,19 @@ kimchi.main = function() { return tabs; }; + var retrieveI18ns = function(url) { + $.ajax({ + url : url, + async : false, + success : function(html) { + $('#main').append(html)}, + error: function(html) {} + }); + }; + var tabConfigUrl = '/config/ui/tabs.xml'; var pluginConfigUrl = '/plugins/{plugin}/ui/config/tab-ext.xml'; + var pluginI18nUrl = 'plugins/{plugin}/i18n.html'; var DEFAULT_HASH; var buildTabs = function(callback) { var tabs = retrieveTabs(tabConfigUrl); @@ -72,6 +83,10 @@ kimchi.main = function() { var url = kimchi.template(pluginConfigUrl, { plugin: p }); + var i18nurl = kimchi.template(pluginI18nUrl, { + plugin: p + }); + retrieveI18ns(i18nurl); tabs.push.apply(tabs, retrieveTabs(url)); }); @@ -85,7 +100,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.0

The improvement concept here is to directly generate JSON on the server and assign it to the i18n variable, rather than inserting nodes into the DOM. Plugins would use a plugin1.i18n= structure to keep plugin strings from colliding with each other, or with the kimchi variables. Adam King (2): Add JS API for fetching i18n JSON Update the i18n tmpl to produce JSON src/kimchi/root.py | 2 + ui/js/src/kimchi.api.js | 18 +++++ ui/js/src/kimchi.main.js | 12 +++- ui/pages/i18n.html.tmpl | 176 ----------------------------------------------- ui/pages/i18n.json.tmpl | 163 +++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 192 insertions(+), 179 deletions(-) delete mode 100644 ui/pages/i18n.html.tmpl create mode 100644 ui/pages/i18n.json.tmpl -- 1.9.0

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@linux.vnet.ibm.com> --- ui/js/src/kimchi.api.js | 18 ++++++++++++++++++ ui/js/src/kimchi.main.js | 12 +++++++++--- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/ui/js/src/kimchi.api.js b/ui/js/src/kimchi.api.js index 7d85fdf..c20db2f 100644 --- a/ui/js/src/kimchi.api.js +++ b/ui/js/src/kimchi.api.js @@ -63,6 +63,24 @@ var kimchi = { }, /** + * Get the i18 strings. + */ + getI18n: function(suc, err, plugin) { + if (plugin==undefined) { + plugin=""; + } + kimchi.requestJSON({ + url : kimchi.url + plugin + '/i18n.json', + type : 'GET', + resend: true, + contentType : 'text/html', // 'application/json', + dataType : 'text', //'json', take the JSON directly rather than parsing after updating the CherryPy config. + 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..1b5aa62 100644 --- a/ui/js/src/kimchi.main.js +++ b/ui/js/src/kimchi.main.js @@ -247,9 +247,15 @@ 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=jQuery.parseJSON(i18nStrings); //take the JSON directly rather than parsing after updating the CherryPy config. + buildTabs(initUI); + }, + function(data){ //error + kimchi.message.error(data.responseJSON.reason); + buildTabs(initUI); + }); }; kimchi.getHelp = function(e) { -- 1.9.0

On 05/15/2014 08:25 AM, Adam King wrote:
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@linux.vnet.ibm.com> --- ui/js/src/kimchi.api.js | 18 ++++++++++++++++++ ui/js/src/kimchi.main.js | 12 +++++++++--- 2 files changed, 27 insertions(+), 3 deletions(-)
diff --git a/ui/js/src/kimchi.api.js b/ui/js/src/kimchi.api.js index 7d85fdf..c20db2f 100644 --- a/ui/js/src/kimchi.api.js +++ b/ui/js/src/kimchi.api.js @@ -63,6 +63,24 @@ var kimchi = { },
/** + * Get the i18 strings. + */ + getI18n: function(suc, err, plugin) { + if (plugin==undefined) { + plugin=""; + } + kimchi.requestJSON({ + url : kimchi.url + plugin + '/i18n.json', + type : 'GET', + resend: true,
+ contentType : 'text/html', // 'application/json', + dataType : 'text', //'json', take the JSON directly rather than parsing after updating the CherryPy config. contentType property can be ignored here because it is used only when we do a POST to the server to inform the server the data sent is in JSON format.
dataType can be remained as "json" that dataType is used for jQuery and server-end doesn't need this property at all. If dataType is set to 'json', jQuery will automatically parse the response text into a JS object and pass it into callback as a parameter. See http://api.jquery.com/jquery.ajax/
+ 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..1b5aa62 100644 --- a/ui/js/src/kimchi.main.js +++ b/ui/js/src/kimchi.main.js @@ -247,9 +247,15 @@ 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=jQuery.parseJSON(i18nStrings); //take the JSON directly rather than parsing after updating the CherryPy config. + buildTabs(initUI); + }, + function(data){ //error + kimchi.message.error(data.responseJSON.reason);
+ buildTabs(initUI); If i18n strings is failed to load, we'd better inform user to retry instead of present a broken UI. + }); };
kimchi.getHelp = function(e) {

Remove html tags from i18n as they are not valid Correct object definition from acceptable JS to valid JSON replacing ' with " in attribute names. Update root.py to make Cheetah render the JSON template. Signed-off-by: Adam King <rak@linux.vnet.ibm.com> --- src/kimchi/root.py | 2 + ui/pages/i18n.html.tmpl | 176 ------------------------------------------------ ui/pages/i18n.json.tmpl | 163 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 165 insertions(+), 176 deletions(-) delete mode 100644 ui/pages/i18n.html.tmpl create mode 100644 ui/pages/i18n.json.tmpl diff --git a/src/kimchi/root.py b/src/kimchi/root.py index 8b1d09b..4d39c80 100644 --- a/src/kimchi/root.py +++ b/src/kimchi/root.py @@ -82,6 +82,8 @@ class Root(Resource): def default(self, page, **kwargs): if page.endswith('.html'): return template.render(page, None) + if page.endswith('.json'): + return template.render(page, None) raise cherrypy.HTTPError(404) @cherrypy.expose diff --git a/ui/pages/i18n.html.tmpl b/ui/pages/i18n.html.tmpl deleted file mode 100644 index 98da828..0000000 --- a/ui/pages/i18n.html.tmpl +++ /dev/null @@ -1,176 +0,0 @@ -#* - * Project Kimchi - * - * Copyright IBM, Corp. 2013 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - *# -#unicode UTF-8 -#import gettext -#from kimchi.cachebust import href -#silent t = gettext.translation($lang.domain, $lang.localedir, languages=$lang.lang) -#silent _ = t.gettext -#silent _t = t.gettext - -<!DOCTYPE html> -<html class="no-js" lang=$lang.lang[0]> -<head> - <meta charset="utf-8"> - <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> - <title>language</title> -</head> -<body> -<script> -var i18n = { - 'KCHAUTH6001E': "$_("The username or password you entered is incorrect. Please try again.")", - 'KCHAUTH6002E': "$_("This field is required.")", - - 'KCHAUTH6001M': "$_("Log in")", - 'KCHAUTH6002M': "$_("Logging in...")", - - 'Host': "$_("Host")", - 'Guests': "$_("Guests")", - 'Templates': "$_("Templates")", - 'Storage': "$_("Storage")", - 'Network': "$_("Network")", - - 'KCHAPI6001E': "$_("Invalid URL. Redireced to home page.")", - 'KCHAPI6002E': "$_("Failed to get application configuration")", - 'KCHAPI6003E': "$_("This is not a valid Linux path")", - 'KCHAPI6004E': "$_("This is not a valid URL.")", - 'KCHAPI6005E': "$_("No such data available.")", - 'KCHAPI6006E': "$_("options needed.")", - 'KCHAPI6007E': "$_("Can not contact the host system. Verify the host system is up and that you have network connectivity to it. HTTP request response %1. ")", - - 'KCHAPI6001M': "$_("Delete Confirmation")", - 'KCHAPI6002M': "$_("OK")", - 'KCHAPI6003M': "$_("Cancel")", - 'KCHAPI6004M': "$_("Confirm")", - 'KCHAPI6005M': "$_("Create")", - 'KCHAPI6006M': "$_("Warning")", - - 'KCHGRD6001M': "$_("Loading...")", - 'KCHGRD6002M': "$_("An error occurs while checking for packages update.")", - 'KCHGRD6003M': "$_("Retry")", - 'KCHGRD6004M': "$_("Detailed message:")", - - 'KCHTMPL6001W': "$_("No iso found")", - - 'KCHTMPL6002E': "$_("This is not a valid ISO file.")", - - 'KCHTMPL6002M': "$_("It will take long time. Do you want to continue?")", - 'KCHTMPL6003M': "$_("This will permanently delete the template. Would you like to continue?")", - - 'KCHHOST6001E': "$_("Unable to shut down system as there are some virtual machines running!")", - - 'KCHHOST6001M': "$_("Max:")", - 'KCHHOST6002M': "$_("Utilization")", - 'KCHHOST6003M': "$_("Available")", - 'KCHHOST6004M': "$_("Read Rate")", - 'KCHHOST6005M': "$_("Write Rate")", - 'KCHHOST6006M': "$_("Received")", - 'KCHHOST6007M': "$_("Sent")", - 'KCHHOST6008M': "$_("Shutting down or restarting host will cause unsaved work lost. Continue to shut down/restarting?")", - - - 'KCHREPO6001M': "$_("Confirm")", - 'KCHREPO6002M': "$_("Repository will be removed permanently and can't be recovered. Do you want to continue?")", - 'KCHREPO6003M': "$_("Repositories")", - 'KCHREPO6004M': "$_("ID")", - 'KCHREPO6005M': "$_("Name")", - 'KCHREPO6006M': "$_("Base URL")", - 'KCHREPO6007M': "$_("Is Mirror")", - 'KCHREPO6008M': "$_("URL Args")", - 'KCHREPO6009M': "$_("Enabled")", - 'KCHREPO6010M': "$_("GPG Check")", - 'KCHREPO6011M': "$_("GPG Key")", - 'KCHREPO6012M': "$_("Add")", - 'KCHREPO6013M': "$_("Edit")", - 'KCHREPO6014M': "$_("Remove")", - 'KCHREPO6015M': "$_("Failed.")", - 'KCHREPO6016M': "$_("Enable")", - 'KCHREPO6017M': "$_("Disable")", - - - 'KCHUPD6001M': "$_("Software Updates")", - 'KCHUPD6002M': "$_("Package Name")", - 'KCHUPD6003M': "$_("Version")", - 'KCHUPD6004M': "$_("Architecture")", - 'KCHUPD6005M': "$_("Repository")", - 'KCHUPD6006M': "$_("Update All")", - 'KCHUPD6007M': "$_("Updating...")", - 'KCHUPD6008M': "$_("Failed to retrieve updates.")", - 'KCHUPD6009M': "$_("Failed to update package(s).")", - - - 'KCHDR6001M': "$_("Debug report will be removed permanently and can't be recovered. Do you want to continue?")", - 'KCHDR6002M': "$_("Debug Reports")", - 'KCHDR6003M': "$_("Name")", - 'KCHDR6005M': "$_("Generated Time")", - 'KCHDR6006M': "$_("Generate")", - 'KCHDR6007M': "$_("Generating...")", - 'KCHDR6008M': "$_("Rename")", - 'KCHDR6009M': "$_("Remove")", - 'KCHDR6010M': "$_("Download")", - 'KCHDR6011M': "$_("Report name should contain only letters, digits and/or hyphen ('-').")", - - 'KCHVM6001M': "$_("This will delete the virtual machine and its virtual disks. This operation cannot be undone. Would you like to continue?")", - 'KCHVM6002M': "$_("Power off Confirmation")", - 'KCHVM6003M': "$_("This action may produce undesirable results, " - "for example unflushed disk cache in the guest. " - "Would you like to continue?")", - 'KCHVM6004M': "$_("Reset Confirmation")", - 'KCHVM6005M': "$_("There is a risk of data loss caused by reset without" - " the guest OS shutdown. Would you like to continue?")", - 'KCHVM6006M': "$_("Shut Down Confirmation")", - 'KCHVM6007M': "$_("Note the guest OS may ignore this request. Would you like to continue?")", - - 'KCHVMCD6001M': "$_("This CDROM will be detached permanently and you can re-attach it. Continue to detach it?")", - 'KCHVMCD6002M': "$_("Attach")", - 'KCHVMCD6003M': "$_("Attaching...")", - 'KCHVMCD6004M': "$_("Replace")", - 'KCHVMCD6005M': "$_("Replacing...")", - 'KCHVMCD6006M': "$_("Successfully attached!")", - 'KCHVMCD6007M': "$_("Successfully replaced!")", - 'KCHVMCD6008M': "$_("Successfully detached!")", - - - 'KCHNET6001E': "$_("The VLAN id must be between 1 and 4094.")", - - 'KCHNET6001M': "$_("unavailable")", - 'KCHNET6002M': "$_("This action will interrupt network connectivity for any virtual machine that depend on this network.")", - 'KCHNET6003M': "$_("Create a network")", - 'KCHNET6004M': "$_("This network is not persistent. Instead of stop, this action will permanently delete it. Would you like to continue?")", - - 'KCHPOOL6001M': "$_("This will permanently delete the storage pool. Would you like to continue?")", - 'KCHPOOL6002M': "$_("This storage pool is empty.")", - 'KCHPOOL6003M': "$_("It will format your disk and you will loose any data in there, are you sure to continue? ")", - 'KCHPOOL6004M': "$_("SCSI Fibre Channel")", - 'KCHPOOL6005M': "$_("No SCSI adapters found.")", - - 'KCHPOOL6001E': "$_("The storage pool name can not be blank.")", - 'KCHPOOL6002E': "$_("The storage pool path can not be blank.")", - 'KCHPOOL6003E': "$_("NFS server mount path can not be blank.")", - 'KCHPOOL6004E': "$_("Invalid storage pool name. It should not contain '/'.")", - 'KCHPOOL6005E': "$_("Invalid NFS mount path.")", - 'KCHPOOL6006E': "$_("No logical device selected.")", - 'KCHPOOL6007E': "$_("The iSCSI target can not be blank.")", - 'KCHPOOL6008E': "$_("Server name can not be blank.")", - 'KCHPOOL6009E': "$_("This is not a valid Server Name or IP. please, modify it.")", - 'KCHPOOL6010M': "$_("Looking for available partitions ...")", - 'KCHPOOL6011M': "$_("No available partitions found.")", - 'KCHPOOL6012M': "$_("This storage pool is not persistent. Instead of deactivate, this action will permanently delete it. Would you like to continue?")" -}; -</script> -</body> -</html> diff --git a/ui/pages/i18n.json.tmpl b/ui/pages/i18n.json.tmpl new file mode 100644 index 0000000..2f6ef73 --- /dev/null +++ b/ui/pages/i18n.json.tmpl @@ -0,0 +1,163 @@ +#* + * Project Kimchi + * + * Copyright IBM, Corp. 2013 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + *# +#unicode UTF-8 +#import gettext +#from kimchi.cachebust import href +#silent t = gettext.translation($lang.domain, $lang.localedir, languages=$lang.lang) +#silent _ = t.gettext +#silent _t = t.gettext +{ + "KCHAUTH6001E": "$_("The username or password you entered is incorrect. Please try again.")", + "KCHAUTH6002E": "$_("This field is required.")", + + "KCHAUTH6001M": "$_("Log in")", + "KCHAUTH6002M": "$_("Logging in...")", + + "Host": "$_("Host")", + "Guests": "$_("Guests")", + "Templates": "$_("Templates")", + "Storage": "$_("Storage")", + "Network": "$_("Network")", + + "KCHAPI6001E": "$_("Invalid URL. Redireced to home page.")", + "KCHAPI6002E": "$_("Failed to get application configuration")", + "KCHAPI6003E": "$_("This is not a valid Linux path")", + "KCHAPI6004E": "$_("This is not a valid URL.")", + "KCHAPI6005E": "$_("No such data available.")", + "KCHAPI6006E": "$_("options needed.")", + "KCHAPI6007E": "$_("Can not contact the host system. Verify the host system is up and that you have network connectivity to it. HTTP request response %1. ")", + + "KCHAPI6001M": "$_("Delete Confirmation")", + "KCHAPI6002M": "$_("OK")", + "KCHAPI6003M": "$_("Cancel")", + "KCHAPI6004M": "$_("Confirm")", + "KCHAPI6005M": "$_("Create")", + "KCHAPI6006M": "$_("Warning")", + + "KCHGRD6001M": "$_("Loading...")", + "KCHGRD6002M": "$_("An error occurs while checking for packages update.")", + "KCHGRD6003M": "$_("Retry")", + "KCHGRD6004M": "$_("Detailed message:")", + + "KCHTMPL6001W": "$_("No iso found")", + + "KCHTMPL6002E": "$_("This is not a valid ISO file.")", + + "KCHTMPL6002M": "$_("It will take long time. Do you want to continue?")", + "KCHTMPL6003M": "$_("This will permanently delete the template. Would you like to continue?")", + + "KCHHOST6001E": "$_("Unable to shut down system as there are some virtual machines running!")", + + "KCHHOST6001M": "$_("Max:")", + "KCHHOST6002M": "$_("Utilization")", + "KCHHOST6003M": "$_("Available")", + "KCHHOST6004M": "$_("Read Rate")", + "KCHHOST6005M": "$_("Write Rate")", + "KCHHOST6006M": "$_("Received")", + "KCHHOST6007M": "$_("Sent")", + "KCHHOST6008M": "$_("Shutting down or restarting host will cause unsaved work lost. Continue to shut down/restarting?")", + + + "KCHREPO6001M": "$_("Confirm")", + "KCHREPO6002M": "$_("Repository will be removed permanently and can't be recovered. Do you want to continue?")", + "KCHREPO6003M": "$_("Repositories")", + "KCHREPO6004M": "$_("ID")", + "KCHREPO6005M": "$_("Name")", + "KCHREPO6006M": "$_("Base URL")", + "KCHREPO6007M": "$_("Is Mirror")", + "KCHREPO6008M": "$_("URL Args")", + "KCHREPO6009M": "$_("Enabled")", + "KCHREPO6010M": "$_("GPG Check")", + "KCHREPO6011M": "$_("GPG Key")", + "KCHREPO6012M": "$_("Add")", + "KCHREPO6013M": "$_("Edit")", + "KCHREPO6014M": "$_("Remove")", + "KCHREPO6015M": "$_("Failed.")", + "KCHREPO6016M": "$_("Enable")", + "KCHREPO6017M": "$_("Disable")", + + + "KCHUPD6001M": "$_("Software Updates")", + "KCHUPD6002M": "$_("Package Name")", + "KCHUPD6003M": "$_("Version")", + "KCHUPD6004M": "$_("Architecture")", + "KCHUPD6005M": "$_("Repository")", + "KCHUPD6006M": "$_("Update All")", + "KCHUPD6007M": "$_("Updating...")", + "KCHUPD6008M": "$_("Failed to retrieve updates.")", + "KCHUPD6009M": "$_("Failed to update package(s).")", + + + "KCHDR6001M": "$_("Debug report will be removed permanently and can't be recovered. Do you want to continue?")", + "KCHDR6002M": "$_("Debug Reports")", + "KCHDR6003M": "$_("Name")", + "KCHDR6005M": "$_("Generated Time")", + "KCHDR6006M": "$_("Generate")", + "KCHDR6007M": "$_("Generating...")", + "KCHDR6008M": "$_("Rename")", + "KCHDR6009M": "$_("Remove")", + "KCHDR6010M": "$_("Download")", + "KCHDR6011M": "$_("Report name should contain only letters, digits and/or hyphen ('-').")", + + "KCHVM6001M": "$_("This will delete the virtual machine and its virtual disks. This operation cannot be undone. Would you like to continue?")", + "KCHVM6002M": "$_("Power off Confirmation")", + "KCHVM6003M": "$_("This action may produce undesirable results, " + "for example unflushed disk cache in the guest. " + "Would you like to continue?")", + "KCHVM6004M": "$_("Reset Confirmation")", + "KCHVM6005M": "$_("There is a risk of data loss caused by reset without" + " the guest OS shutdown. Would you like to continue?")", + "KCHVM6006M": "$_("Shut Down Confirmation")", + "KCHVM6007M": "$_("Note the guest OS may ignore this request. Would you like to continue?")", + + "KCHVMCD6001M": "$_("This CDROM will be detached permanently and you can re-attach it. Continue to detach it?")", + "KCHVMCD6002M": "$_("Attach")", + "KCHVMCD6003M": "$_("Attaching...")", + "KCHVMCD6004M": "$_("Replace")", + "KCHVMCD6005M": "$_("Replacing...")", + "KCHVMCD6006M": "$_("Successfully attached!")", + "KCHVMCD6007M": "$_("Successfully replaced!")", + "KCHVMCD6008M": "$_("Successfully detached!")", + + + "KCHNET6001E": "$_("The VLAN id must be between 1 and 4094.")", + + "KCHNET6001M": "$_("unavailable")", + "KCHNET6002M": "$_("This action will interrupt network connectivity for any virtual machine that depend on this network.")", + "KCHNET6003M": "$_("Create a network")", + "KCHNET6004M": "$_("This network is not persistent. Instead of stop, this action will permanently delete it. Would you like to continue?")", + + "KCHPOOL6001M": "$_("This will permanently delete the storage pool. Would you like to continue?")", + "KCHPOOL6002M": "$_("This storage pool is empty.")", + "KCHPOOL6003M": "$_("It will format your disk and you will loose any data in there, are you sure to continue? ")", + "KCHPOOL6004M": "$_("SCSI Fibre Channel")", + "KCHPOOL6005M": "$_("No SCSI adapters found.")", + + "KCHPOOL6001E": "$_("The storage pool name can not be blank.")", + "KCHPOOL6002E": "$_("The storage pool path can not be blank.")", + "KCHPOOL6003E": "$_("NFS server mount path can not be blank.")", + "KCHPOOL6004E": "$_("Invalid storage pool name. It should not contain '/'.")", + "KCHPOOL6005E": "$_("Invalid NFS mount path.")", + "KCHPOOL6006E": "$_("No logical device selected.")", + "KCHPOOL6007E": "$_("The iSCSI target can not be blank.")", + "KCHPOOL6008E": "$_("Server name can not be blank.")", + "KCHPOOL6009E": "$_("This is not a valid Server Name or IP. please, modify it.")", + "KCHPOOL6010M": "$_("Looking for available partitions ...")", + "KCHPOOL6011M": "$_("No available partitions found.")", + "KCHPOOL6012M": "$_("This storage pool is not persistent. Instead of deactivate, this action will permanently delete it. Would you like to continue?")" +} -- 1.9.0

On 05/14/2014 08:25 PM, Adam King wrote:
+ if page.endswith('.json'): + return template.render(page, None) I am sure there is a better way to accomplish this, but I haven't got it yet. Someone with a little more CherryPy expertise?
-- Adam King <rak@linux.vnet.ibm.com> IBM CSI

On 05/15/2014 08:35 AM, Adam King wrote:
On 05/14/2014 08:25 PM, Adam King wrote:
+ if page.endswith('.json'): + return template.render(page, None) I am sure there is a better way to accomplish this, but I haven't got it yet. Someone with a little more CherryPy expertise? I will try it. seem I have tried it before and it can works when meina proposed to use json instead of html.
-- Thanks and best regards! Sheldon Feng(冯少合)<shaohef@linux.vnet.ibm.com> IBM Linux Technology Center

On 05/15/2014 08:25 AM, Adam King wrote:
The improvement concept here is to directly generate JSON on the server and assign it to the i18n variable, rather than inserting nodes into the DOM. Plugins would use a plugin1.i18n= structure to keep plugin strings from colliding with each other, or with the kimchi variables. Great! It's the right way to directly use JSON file instead of HTML file.
Adam King (2): Add JS API for fetching i18n JSON Update the i18n tmpl to produce JSON
src/kimchi/root.py | 2 + ui/js/src/kimchi.api.js | 18 +++++ ui/js/src/kimchi.main.js | 12 +++- ui/pages/i18n.html.tmpl | 176 ----------------------------------------------- ui/pages/i18n.json.tmpl | 163 +++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 192 insertions(+), 179 deletions(-) delete mode 100644 ui/pages/i18n.html.tmpl create mode 100644 ui/pages/i18n.json.tmpl

On 05/15/2014 04:46 PM, Hongliang Wang wrote:
On 05/15/2014 08:25 AM, Adam King wrote:
The improvement concept here is to directly generate JSON on the server and assign it to the i18n variable, rather than inserting nodes into the DOM. Plugins would use a plugin1.i18n= structure to keep plugin strings from colliding with each other, or with the kimchi variables. Great! It's the right way to directly use JSON file instead of HTML file.
seems all agree JSON file. :-)
Adam King (2): Add JS API for fetching i18n JSON Update the i18n tmpl to produce JSON
src/kimchi/root.py | 2 + ui/js/src/kimchi.api.js | 18 +++++ ui/js/src/kimchi.main.js | 12 +++- ui/pages/i18n.html.tmpl | 176 ----------------------------------------------- ui/pages/i18n.json.tmpl | 163 +++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 192 insertions(+), 179 deletions(-) delete mode 100644 ui/pages/i18n.html.tmpl create mode 100644 ui/pages/i18n.json.tmpl
_______________________________________________ Kimchi-devel mailing list Kimchi-devel@ovirt.org http://lists.ovirt.org/mailman/listinfo/kimchi-devel
-- Thanks and best regards! Sheldon Feng(冯少合)<shaohef@linux.vnet.ibm.com> IBM Linux Technology Center

On 05/14/2014 08:19 PM, shaohef@linux.vnet.ibm.com wrote:
From: ShaoHe Feng <shaohef@linux.vnet.ibm.com>
Apparently, in plugin code there is no way to insert new entries into Kimchi ./ui/pages/i18n.html.tmpl, so every plugin should provide its own i18n.html.tmpl.
each plugin provides a "plugins/plugin-name/ui/pages/i18n.html.tmpl", and maps it to the URI "plugins/plugin-name/i18n.html". This is already supported by the kimchi back-end. What we have to do is just to load "plugins/plugin-name/i18n.html" in the front-end code.
Signed-off-by: ShaoHe Feng <shaohef@linux.vnet.ibm.com> --- ui/js/src/kimchi.api.js | 3 ++- ui/js/src/kimchi.main.js | 19 ++++++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-)
diff --git a/ui/js/src/kimchi.api.js b/ui/js/src/kimchi.api.js index 7d85fdf..d4d92d8 100644 --- a/ui/js/src/kimchi.api.js +++ b/ui/js/src/kimchi.api.js @@ -558,13 +558,14 @@ var kimchi = { }); },
- listPlugins : function(suc, err) { + listPlugins : function(suc, err, async) { kimchi.requestJSON({ url : kimchi.url + 'plugins', type : 'GET', contentType : 'application/json', dataType : 'json', resend: true,
+ async: async ? async : true, The value will always be *true*.
The expression means: if async is true, then return true; else return true.
success : suc, error : err }); diff --git a/ui/js/src/kimchi.main.js b/ui/js/src/kimchi.main.js index 86fed5b..82778cc 100644 --- a/ui/js/src/kimchi.main.js +++ b/ui/js/src/kimchi.main.js @@ -62,8 +62,19 @@ kimchi.main = function() { return tabs; };
+ var retrieveI18ns = function(url) { + $.ajax({ + url : url, + async : false, + success : function(html) { + $('#main').append(html)}, + error: function(html) {} + }); + }; + var tabConfigUrl = '/config/ui/tabs.xml'; var pluginConfigUrl = '/plugins/{plugin}/ui/config/tab-ext.xml'; + var pluginI18nUrl = 'plugins/{plugin}/i18n.html'; var DEFAULT_HASH; var buildTabs = function(callback) { var tabs = retrieveTabs(tabConfigUrl); @@ -72,6 +83,10 @@ kimchi.main = function() { var url = kimchi.template(pluginConfigUrl, { plugin: p }); + var i18nurl = kimchi.template(pluginI18nUrl, { + plugin: p + }); + retrieveI18ns(i18nurl); tabs.push.apply(tabs, retrieveTabs(url)); });
@@ -85,7 +100,9 @@ kimchi.main = function() { $('#nav-menu').append(genTabs(tabs));
callback && callback(); - }); + }, function(data) { + kimchi.message.error(data.responseJSON.reason); + }, true); };
var onLanguageChanged = function(lang) {

From: ShaoHe Feng <shaohef@linux.vnet.ibm.com> still need to imporve to load all plugins i18n string. V1 -> V2: set the Content-Type as application/json The improvement concept here is to directly generate JSON on the server and assign it to the i18n variable, rather than inserting nodes into the DOM. Plugins would use a plugin1.i18n= structure to keep plugin strings from colliding with each other, or with the kimchi variables. ShaoHe Feng (3): Update root.py to make Cheetah render the JSON template. Update the i18n tmpl to produce JSON Add JS API for fetching i18n JSON src/kimchi/root.py | 5 ++ src/kimchi/template.py | 34 +++++---- ui/js/src/kimchi.api.js | 17 +++++ ui/js/src/kimchi.main.js | 12 +++- ui/pages/i18n.html.tmpl | 176 ----------------------------------------------- ui/pages/i18n.json.tmpl | 163 +++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 213 insertions(+), 194 deletions(-) delete mode 100644 ui/pages/i18n.html.tmpl create mode 100644 ui/pages/i18n.json.tmpl -- 1.9.0

From: ShaoHe Feng <shaohef@linux.vnet.ibm.com> when the request are json files, set the Content-Type as application/json. Signed-off-by: Adam King <rak@linux.vnet.ibm.com> Signed-off-by: ShaoHe Feng <shaohef@linux.vnet.ibm.com> --- src/kimchi/root.py | 5 +++++ src/kimchi/template.py | 34 +++++++++++++++++++--------------- 2 files changed, 24 insertions(+), 15 deletions(-) diff --git a/src/kimchi/root.py b/src/kimchi/root.py index 8b1d09b..1cebfd1 100644 --- a/src/kimchi/root.py +++ b/src/kimchi/root.py @@ -82,6 +82,11 @@ class Root(Resource): def default(self, page, **kwargs): if page.endswith('.html'): return template.render(page, None) + if page.endswith('.json'): + cherrypy.response.headers['Content-Type'] = \ + 'application/json;charset=utf-8' + context = template.render_cheetah_file(page, None) + return context.encode("utf-8") raise cherrypy.HTTPError(404) @cherrypy.expose diff --git a/src/kimchi/template.py b/src/kimchi/template.py index 60cd818..146e735 100644 --- a/src/kimchi/template.py +++ b/src/kimchi/template.py @@ -82,26 +82,30 @@ def can_accept_html(): can_accept('*/*') +def render_cheetah_file(resource, data): + paths = cherrypy.request.app.root.paths + filename = paths.get_template_path(resource) + try: + params = {'data': data} + lang = validate_language(get_lang()) + gettext_conf = {'domain': 'kimchi', + 'localedir': paths.mo_dir, + 'lang': [lang]} + params['lang'] = gettext_conf + return Template(file=filename, searchList=params).respond() + except OSError, e: + if e.errno == errno.ENOENT: + raise cherrypy.HTTPError(404) + else: + raise + + def render(resource, data): if can_accept('application/json'): cherrypy.response.headers['Content-Type'] = \ 'application/json;charset=utf-8' return json.dumps(data, indent=2, separators=(',', ':')) elif can_accept_html(): - paths = cherrypy.request.app.root.paths - filename = paths.get_template_path(resource) - try: - params = {'data': data} - lang = validate_language(get_lang()) - gettext_conf = {'domain': 'kimchi', - 'localedir': paths.mo_dir, - 'lang': [lang]} - params['lang'] = gettext_conf - return Template(file=filename, searchList=params).respond() - except OSError, e: - if e.errno == errno.ENOENT: - raise cherrypy.HTTPError(404) - else: - raise + return render_cheetah_file(resource, data) else: raise cherrypy.HTTPError(406) -- 1.9.0

From: ShaoHe Feng <shaohef@linux.vnet.ibm.com> Remove html tags from i18n as they are not valid Correct object definition from acceptable JS to valid JSON replacing ' with " in attribute names. Update root.py to make Cheetah render the JSON template. Signed-off-by: Adam King <rak@linux.vnet.ibm.com> Signed-off-by: ShaoHe Feng <shaohef@linux.vnet.ibm.com> --- ui/pages/i18n.html.tmpl | 176 ------------------------------------------------ ui/pages/i18n.json.tmpl | 163 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 163 insertions(+), 176 deletions(-) delete mode 100644 ui/pages/i18n.html.tmpl create mode 100644 ui/pages/i18n.json.tmpl diff --git a/ui/pages/i18n.html.tmpl b/ui/pages/i18n.html.tmpl deleted file mode 100644 index 98da828..0000000 --- a/ui/pages/i18n.html.tmpl +++ /dev/null @@ -1,176 +0,0 @@ -#* - * Project Kimchi - * - * Copyright IBM, Corp. 2013 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - *# -#unicode UTF-8 -#import gettext -#from kimchi.cachebust import href -#silent t = gettext.translation($lang.domain, $lang.localedir, languages=$lang.lang) -#silent _ = t.gettext -#silent _t = t.gettext - -<!DOCTYPE html> -<html class="no-js" lang=$lang.lang[0]> -<head> - <meta charset="utf-8"> - <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> - <title>language</title> -</head> -<body> -<script> -var i18n = { - 'KCHAUTH6001E': "$_("The username or password you entered is incorrect. Please try again.")", - 'KCHAUTH6002E': "$_("This field is required.")", - - 'KCHAUTH6001M': "$_("Log in")", - 'KCHAUTH6002M': "$_("Logging in...")", - - 'Host': "$_("Host")", - 'Guests': "$_("Guests")", - 'Templates': "$_("Templates")", - 'Storage': "$_("Storage")", - 'Network': "$_("Network")", - - 'KCHAPI6001E': "$_("Invalid URL. Redireced to home page.")", - 'KCHAPI6002E': "$_("Failed to get application configuration")", - 'KCHAPI6003E': "$_("This is not a valid Linux path")", - 'KCHAPI6004E': "$_("This is not a valid URL.")", - 'KCHAPI6005E': "$_("No such data available.")", - 'KCHAPI6006E': "$_("options needed.")", - 'KCHAPI6007E': "$_("Can not contact the host system. Verify the host system is up and that you have network connectivity to it. HTTP request response %1. ")", - - 'KCHAPI6001M': "$_("Delete Confirmation")", - 'KCHAPI6002M': "$_("OK")", - 'KCHAPI6003M': "$_("Cancel")", - 'KCHAPI6004M': "$_("Confirm")", - 'KCHAPI6005M': "$_("Create")", - 'KCHAPI6006M': "$_("Warning")", - - 'KCHGRD6001M': "$_("Loading...")", - 'KCHGRD6002M': "$_("An error occurs while checking for packages update.")", - 'KCHGRD6003M': "$_("Retry")", - 'KCHGRD6004M': "$_("Detailed message:")", - - 'KCHTMPL6001W': "$_("No iso found")", - - 'KCHTMPL6002E': "$_("This is not a valid ISO file.")", - - 'KCHTMPL6002M': "$_("It will take long time. Do you want to continue?")", - 'KCHTMPL6003M': "$_("This will permanently delete the template. Would you like to continue?")", - - 'KCHHOST6001E': "$_("Unable to shut down system as there are some virtual machines running!")", - - 'KCHHOST6001M': "$_("Max:")", - 'KCHHOST6002M': "$_("Utilization")", - 'KCHHOST6003M': "$_("Available")", - 'KCHHOST6004M': "$_("Read Rate")", - 'KCHHOST6005M': "$_("Write Rate")", - 'KCHHOST6006M': "$_("Received")", - 'KCHHOST6007M': "$_("Sent")", - 'KCHHOST6008M': "$_("Shutting down or restarting host will cause unsaved work lost. Continue to shut down/restarting?")", - - - 'KCHREPO6001M': "$_("Confirm")", - 'KCHREPO6002M': "$_("Repository will be removed permanently and can't be recovered. Do you want to continue?")", - 'KCHREPO6003M': "$_("Repositories")", - 'KCHREPO6004M': "$_("ID")", - 'KCHREPO6005M': "$_("Name")", - 'KCHREPO6006M': "$_("Base URL")", - 'KCHREPO6007M': "$_("Is Mirror")", - 'KCHREPO6008M': "$_("URL Args")", - 'KCHREPO6009M': "$_("Enabled")", - 'KCHREPO6010M': "$_("GPG Check")", - 'KCHREPO6011M': "$_("GPG Key")", - 'KCHREPO6012M': "$_("Add")", - 'KCHREPO6013M': "$_("Edit")", - 'KCHREPO6014M': "$_("Remove")", - 'KCHREPO6015M': "$_("Failed.")", - 'KCHREPO6016M': "$_("Enable")", - 'KCHREPO6017M': "$_("Disable")", - - - 'KCHUPD6001M': "$_("Software Updates")", - 'KCHUPD6002M': "$_("Package Name")", - 'KCHUPD6003M': "$_("Version")", - 'KCHUPD6004M': "$_("Architecture")", - 'KCHUPD6005M': "$_("Repository")", - 'KCHUPD6006M': "$_("Update All")", - 'KCHUPD6007M': "$_("Updating...")", - 'KCHUPD6008M': "$_("Failed to retrieve updates.")", - 'KCHUPD6009M': "$_("Failed to update package(s).")", - - - 'KCHDR6001M': "$_("Debug report will be removed permanently and can't be recovered. Do you want to continue?")", - 'KCHDR6002M': "$_("Debug Reports")", - 'KCHDR6003M': "$_("Name")", - 'KCHDR6005M': "$_("Generated Time")", - 'KCHDR6006M': "$_("Generate")", - 'KCHDR6007M': "$_("Generating...")", - 'KCHDR6008M': "$_("Rename")", - 'KCHDR6009M': "$_("Remove")", - 'KCHDR6010M': "$_("Download")", - 'KCHDR6011M': "$_("Report name should contain only letters, digits and/or hyphen ('-').")", - - 'KCHVM6001M': "$_("This will delete the virtual machine and its virtual disks. This operation cannot be undone. Would you like to continue?")", - 'KCHVM6002M': "$_("Power off Confirmation")", - 'KCHVM6003M': "$_("This action may produce undesirable results, " - "for example unflushed disk cache in the guest. " - "Would you like to continue?")", - 'KCHVM6004M': "$_("Reset Confirmation")", - 'KCHVM6005M': "$_("There is a risk of data loss caused by reset without" - " the guest OS shutdown. Would you like to continue?")", - 'KCHVM6006M': "$_("Shut Down Confirmation")", - 'KCHVM6007M': "$_("Note the guest OS may ignore this request. Would you like to continue?")", - - 'KCHVMCD6001M': "$_("This CDROM will be detached permanently and you can re-attach it. Continue to detach it?")", - 'KCHVMCD6002M': "$_("Attach")", - 'KCHVMCD6003M': "$_("Attaching...")", - 'KCHVMCD6004M': "$_("Replace")", - 'KCHVMCD6005M': "$_("Replacing...")", - 'KCHVMCD6006M': "$_("Successfully attached!")", - 'KCHVMCD6007M': "$_("Successfully replaced!")", - 'KCHVMCD6008M': "$_("Successfully detached!")", - - - 'KCHNET6001E': "$_("The VLAN id must be between 1 and 4094.")", - - 'KCHNET6001M': "$_("unavailable")", - 'KCHNET6002M': "$_("This action will interrupt network connectivity for any virtual machine that depend on this network.")", - 'KCHNET6003M': "$_("Create a network")", - 'KCHNET6004M': "$_("This network is not persistent. Instead of stop, this action will permanently delete it. Would you like to continue?")", - - 'KCHPOOL6001M': "$_("This will permanently delete the storage pool. Would you like to continue?")", - 'KCHPOOL6002M': "$_("This storage pool is empty.")", - 'KCHPOOL6003M': "$_("It will format your disk and you will loose any data in there, are you sure to continue? ")", - 'KCHPOOL6004M': "$_("SCSI Fibre Channel")", - 'KCHPOOL6005M': "$_("No SCSI adapters found.")", - - 'KCHPOOL6001E': "$_("The storage pool name can not be blank.")", - 'KCHPOOL6002E': "$_("The storage pool path can not be blank.")", - 'KCHPOOL6003E': "$_("NFS server mount path can not be blank.")", - 'KCHPOOL6004E': "$_("Invalid storage pool name. It should not contain '/'.")", - 'KCHPOOL6005E': "$_("Invalid NFS mount path.")", - 'KCHPOOL6006E': "$_("No logical device selected.")", - 'KCHPOOL6007E': "$_("The iSCSI target can not be blank.")", - 'KCHPOOL6008E': "$_("Server name can not be blank.")", - 'KCHPOOL6009E': "$_("This is not a valid Server Name or IP. please, modify it.")", - 'KCHPOOL6010M': "$_("Looking for available partitions ...")", - 'KCHPOOL6011M': "$_("No available partitions found.")", - 'KCHPOOL6012M': "$_("This storage pool is not persistent. Instead of deactivate, this action will permanently delete it. Would you like to continue?")" -}; -</script> -</body> -</html> diff --git a/ui/pages/i18n.json.tmpl b/ui/pages/i18n.json.tmpl new file mode 100644 index 0000000..2f6ef73 --- /dev/null +++ b/ui/pages/i18n.json.tmpl @@ -0,0 +1,163 @@ +#* + * Project Kimchi + * + * Copyright IBM, Corp. 2013 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + *# +#unicode UTF-8 +#import gettext +#from kimchi.cachebust import href +#silent t = gettext.translation($lang.domain, $lang.localedir, languages=$lang.lang) +#silent _ = t.gettext +#silent _t = t.gettext +{ + "KCHAUTH6001E": "$_("The username or password you entered is incorrect. Please try again.")", + "KCHAUTH6002E": "$_("This field is required.")", + + "KCHAUTH6001M": "$_("Log in")", + "KCHAUTH6002M": "$_("Logging in...")", + + "Host": "$_("Host")", + "Guests": "$_("Guests")", + "Templates": "$_("Templates")", + "Storage": "$_("Storage")", + "Network": "$_("Network")", + + "KCHAPI6001E": "$_("Invalid URL. Redireced to home page.")", + "KCHAPI6002E": "$_("Failed to get application configuration")", + "KCHAPI6003E": "$_("This is not a valid Linux path")", + "KCHAPI6004E": "$_("This is not a valid URL.")", + "KCHAPI6005E": "$_("No such data available.")", + "KCHAPI6006E": "$_("options needed.")", + "KCHAPI6007E": "$_("Can not contact the host system. Verify the host system is up and that you have network connectivity to it. HTTP request response %1. ")", + + "KCHAPI6001M": "$_("Delete Confirmation")", + "KCHAPI6002M": "$_("OK")", + "KCHAPI6003M": "$_("Cancel")", + "KCHAPI6004M": "$_("Confirm")", + "KCHAPI6005M": "$_("Create")", + "KCHAPI6006M": "$_("Warning")", + + "KCHGRD6001M": "$_("Loading...")", + "KCHGRD6002M": "$_("An error occurs while checking for packages update.")", + "KCHGRD6003M": "$_("Retry")", + "KCHGRD6004M": "$_("Detailed message:")", + + "KCHTMPL6001W": "$_("No iso found")", + + "KCHTMPL6002E": "$_("This is not a valid ISO file.")", + + "KCHTMPL6002M": "$_("It will take long time. Do you want to continue?")", + "KCHTMPL6003M": "$_("This will permanently delete the template. Would you like to continue?")", + + "KCHHOST6001E": "$_("Unable to shut down system as there are some virtual machines running!")", + + "KCHHOST6001M": "$_("Max:")", + "KCHHOST6002M": "$_("Utilization")", + "KCHHOST6003M": "$_("Available")", + "KCHHOST6004M": "$_("Read Rate")", + "KCHHOST6005M": "$_("Write Rate")", + "KCHHOST6006M": "$_("Received")", + "KCHHOST6007M": "$_("Sent")", + "KCHHOST6008M": "$_("Shutting down or restarting host will cause unsaved work lost. Continue to shut down/restarting?")", + + + "KCHREPO6001M": "$_("Confirm")", + "KCHREPO6002M": "$_("Repository will be removed permanently and can't be recovered. Do you want to continue?")", + "KCHREPO6003M": "$_("Repositories")", + "KCHREPO6004M": "$_("ID")", + "KCHREPO6005M": "$_("Name")", + "KCHREPO6006M": "$_("Base URL")", + "KCHREPO6007M": "$_("Is Mirror")", + "KCHREPO6008M": "$_("URL Args")", + "KCHREPO6009M": "$_("Enabled")", + "KCHREPO6010M": "$_("GPG Check")", + "KCHREPO6011M": "$_("GPG Key")", + "KCHREPO6012M": "$_("Add")", + "KCHREPO6013M": "$_("Edit")", + "KCHREPO6014M": "$_("Remove")", + "KCHREPO6015M": "$_("Failed.")", + "KCHREPO6016M": "$_("Enable")", + "KCHREPO6017M": "$_("Disable")", + + + "KCHUPD6001M": "$_("Software Updates")", + "KCHUPD6002M": "$_("Package Name")", + "KCHUPD6003M": "$_("Version")", + "KCHUPD6004M": "$_("Architecture")", + "KCHUPD6005M": "$_("Repository")", + "KCHUPD6006M": "$_("Update All")", + "KCHUPD6007M": "$_("Updating...")", + "KCHUPD6008M": "$_("Failed to retrieve updates.")", + "KCHUPD6009M": "$_("Failed to update package(s).")", + + + "KCHDR6001M": "$_("Debug report will be removed permanently and can't be recovered. Do you want to continue?")", + "KCHDR6002M": "$_("Debug Reports")", + "KCHDR6003M": "$_("Name")", + "KCHDR6005M": "$_("Generated Time")", + "KCHDR6006M": "$_("Generate")", + "KCHDR6007M": "$_("Generating...")", + "KCHDR6008M": "$_("Rename")", + "KCHDR6009M": "$_("Remove")", + "KCHDR6010M": "$_("Download")", + "KCHDR6011M": "$_("Report name should contain only letters, digits and/or hyphen ('-').")", + + "KCHVM6001M": "$_("This will delete the virtual machine and its virtual disks. This operation cannot be undone. Would you like to continue?")", + "KCHVM6002M": "$_("Power off Confirmation")", + "KCHVM6003M": "$_("This action may produce undesirable results, " + "for example unflushed disk cache in the guest. " + "Would you like to continue?")", + "KCHVM6004M": "$_("Reset Confirmation")", + "KCHVM6005M": "$_("There is a risk of data loss caused by reset without" + " the guest OS shutdown. Would you like to continue?")", + "KCHVM6006M": "$_("Shut Down Confirmation")", + "KCHVM6007M": "$_("Note the guest OS may ignore this request. Would you like to continue?")", + + "KCHVMCD6001M": "$_("This CDROM will be detached permanently and you can re-attach it. Continue to detach it?")", + "KCHVMCD6002M": "$_("Attach")", + "KCHVMCD6003M": "$_("Attaching...")", + "KCHVMCD6004M": "$_("Replace")", + "KCHVMCD6005M": "$_("Replacing...")", + "KCHVMCD6006M": "$_("Successfully attached!")", + "KCHVMCD6007M": "$_("Successfully replaced!")", + "KCHVMCD6008M": "$_("Successfully detached!")", + + + "KCHNET6001E": "$_("The VLAN id must be between 1 and 4094.")", + + "KCHNET6001M": "$_("unavailable")", + "KCHNET6002M": "$_("This action will interrupt network connectivity for any virtual machine that depend on this network.")", + "KCHNET6003M": "$_("Create a network")", + "KCHNET6004M": "$_("This network is not persistent. Instead of stop, this action will permanently delete it. Would you like to continue?")", + + "KCHPOOL6001M": "$_("This will permanently delete the storage pool. Would you like to continue?")", + "KCHPOOL6002M": "$_("This storage pool is empty.")", + "KCHPOOL6003M": "$_("It will format your disk and you will loose any data in there, are you sure to continue? ")", + "KCHPOOL6004M": "$_("SCSI Fibre Channel")", + "KCHPOOL6005M": "$_("No SCSI adapters found.")", + + "KCHPOOL6001E": "$_("The storage pool name can not be blank.")", + "KCHPOOL6002E": "$_("The storage pool path can not be blank.")", + "KCHPOOL6003E": "$_("NFS server mount path can not be blank.")", + "KCHPOOL6004E": "$_("Invalid storage pool name. It should not contain '/'.")", + "KCHPOOL6005E": "$_("Invalid NFS mount path.")", + "KCHPOOL6006E": "$_("No logical device selected.")", + "KCHPOOL6007E": "$_("The iSCSI target can not be blank.")", + "KCHPOOL6008E": "$_("Server name can not be blank.")", + "KCHPOOL6009E": "$_("This is not a valid Server Name or IP. please, modify it.")", + "KCHPOOL6010M": "$_("Looking for available partitions ...")", + "KCHPOOL6011M": "$_("No available partitions found.")", + "KCHPOOL6012M": "$_("This storage pool is not persistent. Instead of deactivate, this action will permanently delete it. Would you like to continue?")" +} -- 1.9.0

From: ShaoHe Feng <shaohef@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@linux.vnet.ibm.com> Signed-off-by: ShaoHe Feng <shaohef@linux.vnet.ibm.com> --- ui/js/src/kimchi.api.js | 17 +++++++++++++++++ ui/js/src/kimchi.main.js | 12 +++++++++--- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/ui/js/src/kimchi.api.js b/ui/js/src/kimchi.api.js index 7d85fdf..b2122a4 100644 --- a/ui/js/src/kimchi.api.js +++ b/ui/js/src/kimchi.api.js @@ -63,6 +63,23 @@ var kimchi = { }, /** + * Get the i18 strings. + */ + getI18n: function(suc, err, plugin) { + if (plugin==undefined) { + plugin=""; + } + kimchi.requestJSON({ + url : kimchi.url + plugin + '/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..70840c1 100644 --- a/ui/js/src/kimchi.main.js +++ b/ui/js/src/kimchi.main.js @@ -247,9 +247,15 @@ 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; //take the JSON directly rather than parsing after updating the CherryPy config. + buildTabs(initUI); + }, + function(data){ //error + i18n={} + buildTabs(initUI); + }); }; kimchi.getHelp = function(e) { -- 1.9.0
participants (4)
-
Adam King
-
Hongliang Wang
-
shaohef@linux.vnet.ibm.com
-
Sheldon