From 1bb389c76d0ddae0c5ab1c14171a0e93cd2526cf Mon Sep 17 00:00:00 2001 From: Stas Vilchik Date: Fri, 23 May 2014 11:22:10 +0200 Subject: [PATCH] SONAR-5334 First frontend integration --- .../src/main/coffee/coding-rules/app.coffee | 6 +++-- .../src/main/coffee/quality-gate/app.coffee | 6 +++-- sonar-server/src/main/js/translate.js | 26 ++++++++++++++++++- 3 files changed, 33 insertions(+), 5 deletions(-) diff --git a/sonar-server/src/main/coffee/coding-rules/app.coffee b/sonar-server/src/main/coffee/coding-rules/app.coffee index 230bdd4e489..fa4996a81b7 100644 --- a/sonar-server/src/main/coffee/coding-rules/app.coffee +++ b/sonar-server/src/main/coffee/coding-rules/app.coffee @@ -350,7 +350,10 @@ requirejs [ appXHR = jQuery.ajax url: "#{baseUrl}/api/rules/app" - jQuery.when(appXHR) + # Message bundles + l10nXHR = window.requestMessages() + + jQuery.when(appXHR, l10nXHR) .done (r) -> App.appState = new Backbone.Model App.state = new Backbone.Model @@ -360,7 +363,6 @@ requirejs [ App.repositories = r.repositories App.statuses = r.statuses App.characteristics = r.characteristics - window.messages = r.messages App.facetPropertyToLabels = 'languages': App.languages diff --git a/sonar-server/src/main/coffee/quality-gate/app.coffee b/sonar-server/src/main/coffee/quality-gate/app.coffee index 1e2e4b52c83..2f6a8720f27 100644 --- a/sonar-server/src/main/coffee/quality-gate/app.coffee +++ b/sonar-server/src/main/coffee/quality-gate/app.coffee @@ -130,11 +130,13 @@ requirejs [ App.canEdit = r.edit App.periods = r.periods App.metrics = r.metrics - window.messages = r.messages qualityGatesXHR = App.qualityGates.fetch() - jQuery.when(qualityGatesXHR, appXHR) + # Message bundles + l10nXHR = window.requestMessages() + + jQuery.when(qualityGatesXHR, appXHR, l10nXHR) .done -> # Remove the initial spinner jQuery('#quality-gate-page-loader').remove() diff --git a/sonar-server/src/main/js/translate.js b/sonar-server/src/main/js/translate.js index f64a6a58d2d..33e38b5f8a3 100644 --- a/sonar-server/src/main/js/translate.js +++ b/sonar-server/src/main/js/translate.js @@ -5,7 +5,7 @@ } }; - window.t = function() { + window.t2 = function() { if (!window.messages) { return window.translate.apply(this, arguments); } @@ -18,6 +18,17 @@ return (window.messages && window.messages[key]) || key; }; + window.t = function() { + var args = Array.prototype.slice.call(arguments, 0), + key = args.join('.'), + storageKey = 'l10n.' + key, + message = localStorage.getItem(storageKey); + if (!message) { + return window.t2.apply(this, arguments); + } + return message; + }; + window.tp = function() { var args = Array.prototype.slice.call(arguments, 0), @@ -58,4 +69,17 @@ return found ? result : key; }; + + window.requestMessages = function() { + var apiUrl = baseUrl + '/api/l10n/index'; + jQuery.get(apiUrl, function(bundle) { + for (var message in bundle) { + if (bundle.hasOwnProperty(message)) { + var storageKey = 'l10n.' + message; + localStorage.setItem(storageKey, bundle[message]); + } + } + }); + }; + })(); -- 2.39.5