[Kimchi-devel] [PATCH V5 5/7] Issue #342: load i18n.html of the plugin
Aline Manera
alinefm at linux.vnet.ibm.com
Mon Jun 9 19:45:49 UTC 2014
On 06/09/2014 07:09 AM, shaohef at linux.vnet.ibm.com wrote:
> 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".
How did you do this map for the sample plugin?
> 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) {
More information about the Kimchi-devel
mailing list