summaryrefslogtreecommitdiff
path: root/web-ui/app/js
diff options
context:
space:
mode:
authorCaio Carrara <ccarrara@thoughtworks.com>2016-06-24 17:15:54 -0300
committerCaio Carrara <ccarrara@thoughtworks.com>2016-06-27 16:39:55 -0300
commit361796f0ff1eb0f450f768749d5c69f5c4f6b1e4 (patch)
tree01e1729ce21feccba9c08fd6e7d8452397d5521a /web-ui/app/js
parent6042a2b1b93d2f2a89c418971d7e12b5a79b3314 (diff)
Updates the i18next to latest version
See: #727
Diffstat (limited to 'web-ui/app/js')
-rw-r--r--web-ui/app/js/helpers/monitored_ajax.js2
-rw-r--r--web-ui/app/js/helpers/view_helper.js2
-rw-r--r--web-ui/app/js/mail_view/ui/forward_box.js2
-rw-r--r--web-ui/app/js/mail_view/ui/reply_box.js2
-rw-r--r--web-ui/app/js/mail_view/ui/send_button.js4
-rw-r--r--web-ui/app/js/main.js5
-rw-r--r--web-ui/app/js/mixins/with_mail_edit_base.js2
-rw-r--r--web-ui/app/js/page/default.js56
-rw-r--r--web-ui/app/js/services/delete_service.js8
-rw-r--r--web-ui/app/js/services/mail_service.js18
-rw-r--r--web-ui/app/js/services/recover_service.js2
-rw-r--r--web-ui/app/js/tags/ui/tag.js2
-rw-r--r--web-ui/app/js/views/i18n.js46
13 files changed, 95 insertions, 56 deletions
diff --git a/web-ui/app/js/helpers/monitored_ajax.js b/web-ui/app/js/helpers/monitored_ajax.js
index 061806fc..bbf85c45 100644
--- a/web-ui/app/js/helpers/monitored_ajax.js
+++ b/web-ui/app/js/helpers/monitored_ajax.js
@@ -49,7 +49,7 @@ define(['page/events', 'views/i18n', 'helpers/browser'], function (events, i18n,
if (!config.skipErrorMessage) {
var msg = (xmlhttprequest.responseJSON && xmlhttprequest.responseJSON.message) ||
messages[textstatus] || messages.error;
- on.trigger(document, events.ui.userAlerts.displayMessage, {message: i18n(msg), class: 'error'});
+ on.trigger(document, events.ui.userAlerts.displayMessage, {message: i18n.t(msg), class: 'error'});
}
if (xmlhttprequest.status === 302) {
diff --git a/web-ui/app/js/helpers/view_helper.js b/web-ui/app/js/helpers/view_helper.js
index f8152ff7..c12e6aaf 100644
--- a/web-ui/app/js/helpers/view_helper.js
+++ b/web-ui/app/js/helpers/view_helper.js
@@ -72,7 +72,7 @@ define(
}
function prependFrom(mail) {
- return i18n(
+ return i18n.t(
'On __date__, <__from__> wrote:\n',
{'date': new Date(mail.header.date).toString(), 'from': mail.header.from}
);
diff --git a/web-ui/app/js/mail_view/ui/forward_box.js b/web-ui/app/js/mail_view/ui/forward_box.js
index f767915c..970fad7f 100644
--- a/web-ui/app/js/mail_view/ui/forward_box.js
+++ b/web-ui/app/js/mail_view/ui/forward_box.js
@@ -31,7 +31,7 @@ define(
return defineComponent(forwardBox, withHideAndShow, withComposeInline);
function forwardBox() {
- var fwd = function(v) { return i18n('fwd') + ': ' + v; };
+ var fwd = function(v) { return i18n.t('fwd') + v; };
this.fetchTargetMail = function (ev) {
this.trigger(document, events.mail.want, { mail: this.attr.ident, caller: this });
diff --git a/web-ui/app/js/mail_view/ui/reply_box.js b/web-ui/app/js/mail_view/ui/reply_box.js
index ba306d7f..fdc9dd0f 100644
--- a/web-ui/app/js/mail_view/ui/reply_box.js
+++ b/web-ui/app/js/mail_view/ui/reply_box.js
@@ -46,7 +46,7 @@ define(
}
};
- var re = function(v) { return i18n('re') + v; };
+ var re = function(v) { return i18n.t('re') + v; };
this.setupReplyBox = function() {
var recipients, body;
diff --git a/web-ui/app/js/mail_view/ui/send_button.js b/web-ui/app/js/mail_view/ui/send_button.js
index c4cf86dc..581a244a 100644
--- a/web-ui/app/js/mail_view/ui/send_button.js
+++ b/web-ui/app/js/mail_view/ui/send_button.js
@@ -89,7 +89,7 @@ define([
}.bind(this)));
this.disableButton();
- this.$node.text(viewHelper.i18n('sending-mail'));
+ this.$node.text(viewHelper.i18n.t('sending-mail'));
this.attr.sendingInProgress = true;
@@ -99,7 +99,7 @@ define([
this.resetButton = function () {
this.attr.sendingInProgress = false;
this.attr.uploading = false;
- this.$node.html(viewHelper.i18n('send-button'));
+ this.$node.html(viewHelper.i18n.t('send-button'));
this.enableButton();
};
diff --git a/web-ui/app/js/main.js b/web-ui/app/js/main.js
index e093e790..b8836a6b 100644
--- a/web-ui/app/js/main.js
+++ b/web-ui/app/js/main.js
@@ -38,7 +38,9 @@ requirejs.config({
'search': 'js/search',
'foundation': 'js/foundation',
'features': 'js/features/features',
- 'i18next': 'bower_components/i18next/i18next.amd',
+ 'i18next': 'bower_components/i18next/i18next',
+ 'i18nextXHRBackend': 'bower_components/i18next-xhr-backend/i18nextXHRBackend',
+ 'i18nextBrowserLanguageDetector': 'bower_components/i18next-browser-languagedetector/i18nextBrowserLanguageDetector',
'quoted-printable': 'bower_components/quoted-printable',
'utf8': 'bower_components/utf8',
'user_settings': 'js/user_settings'
@@ -68,6 +70,7 @@ require(
function(compose, registry, advice, withLogging, debug, events, initializeDefault, _monkeyPatched) {
'use strict';
+
window.Pixelated = window.Pixelated || {};
window.Pixelated.events = events;
diff --git a/web-ui/app/js/mixins/with_mail_edit_base.js b/web-ui/app/js/mixins/with_mail_edit_base.js
index 41de162c..a60cce03 100644
--- a/web-ui/app/js/mixins/with_mail_edit_base.js
+++ b/web-ui/app/js/mixins/with_mail_edit_base.js
@@ -147,7 +147,7 @@ define(
} else {
this.trigger(
events.ui.userAlerts.displayMessage,
- {message: i18n('One or more of the recipients are not valid emails')}
+ {message: i18n.t('One or more of the recipients are not valid emails')}
);
this.trigger(events.mail.send_failed);
}
diff --git a/web-ui/app/js/page/default.js b/web-ui/app/js/page/default.js
index 965fb577..ecaedfd8 100644
--- a/web-ui/app/js/page/default.js
+++ b/web-ui/app/js/page/default.js
@@ -97,46 +97,48 @@ define(
'use strict';
function initialize(path) {
viewI18n.init(path + '/assets/');
- paneContractExpand.attachTo(document);
+ viewI18n.loaded(function() {
+ paneContractExpand.attachTo(document);
- userAlerts.attachTo('#user-alerts');
+ userAlerts.attachTo('#user-alerts');
- mailList.attachTo('#mail-list');
- mailListActions.attachTo('#list-actions');
+ mailList.attachTo('#mail-list');
+ mailListActions.attachTo('#list-actions');
- searchTrigger.attachTo('#search-trigger');
- resultsHighlighter.attachTo(document);
+ searchTrigger.attachTo('#search-trigger');
+ resultsHighlighter.attachTo(document);
- mailSender.attachTo(document);
+ mailSender.attachTo(document);
- mailService.attachTo(document);
- deleteService.attachTo(document);
- recoverService.attachTo(document);
+ mailService.attachTo(document);
+ deleteService.attachTo(document);
+ recoverService.attachTo(document);
- tags.attachTo(document);
- tagList.attachTo('#tag-list');
+ tags.attachTo(document);
+ tagList.attachTo('#tag-list');
- router.attachTo(document);
+ router.attachTo(document);
- rightPaneDispatcher.attachTo(document);
- middlePaneDispatcher.attachTo(document);
- leftPaneDispatcher.attachTo(document);
+ rightPaneDispatcher.attachTo(document);
+ middlePaneDispatcher.attachTo(document);
+ leftPaneDispatcher.attachTo(document);
- offCanvas.attachTo(document);
- userSettings.attachTo(document);
- userSettingsIcon.attachTo('#user-settings-icon');
- logout.attachTo('#logout');
- logoutShortcut.attachTo('#logout-shortcut');
- version.attachTo('.version');
+ offCanvas.attachTo(document);
+ userSettings.attachTo(document);
+ userSettingsIcon.attachTo('#user-settings-icon');
+ logout.attachTo('#logout');
+ logoutShortcut.attachTo('#logout-shortcut');
+ version.attachTo('.version');
- feedback.attachTo('#feedback');
- feedbackSender.attachTo(document);
+ feedback.attachTo('#feedback');
+ feedbackSender.attachTo(document);
- unreadCountTitle.attachTo(document);
+ unreadCountTitle.attachTo(document);
- pixLogo.attachTo(document);
+ pixLogo.attachTo(document);
- $.ajaxSetup({headers: {'X-XSRF-TOKEN': browser.getCookie('XSRF-TOKEN')}});
+ $.ajaxSetup({headers: {'X-XSRF-TOKEN': browser.getCookie('XSRF-TOKEN')}});
+ });
}
return initialize;
diff --git a/web-ui/app/js/services/delete_service.js b/web-ui/app/js/services/delete_service.js
index 4097ea7e..0dfc1bdb 100644
--- a/web-ui/app/js/services/delete_service.js
+++ b/web-ui/app/js/services/delete_service.js
@@ -22,14 +22,14 @@ define(['flight/lib/component', 'page/events', 'views/i18n'], function (defineCo
this.successDeleteMessageFor = function(mail) {
return mail.isInTrash() ?
- i18n('delete-single') :
- i18n('trash-single');
+ i18n.t('delete-single') :
+ i18n.t('trash-single');
};
this.successDeleteManyMessageFor = function(mail) {
return mail.isInTrash() ?
- i18n('delete-bulk') :
- i18n('trash-bulk');
+ i18n.t('delete-bulk') :
+ i18n.t('trash-bulk');
};
this.deleteEmail = function (event, data) {
diff --git a/web-ui/app/js/services/mail_service.js b/web-ui/app/js/services/mail_service.js
index 412451cb..529a43b8 100644
--- a/web-ui/app/js/services/mail_service.js
+++ b/web-ui/app/js/services/mail_service.js
@@ -60,9 +60,9 @@ define(
};
var failure = function (resp) {
- var msg = i18n('Could not update mail tags');
+ var msg = i18n.t('Could not update mail tags');
if (resp.status === 403) {
- msg = i18n('Invalid tag name');
+ msg = i18n.t('Invalid tag name');
}
this.trigger(document, events.ui.userAlerts.displayMessage, { message: msg });
};
@@ -128,7 +128,7 @@ define(
var mails = dataToRecover.mails || [dataToRecover.mail];
this.refreshMails();
- this.trigger(document, events.ui.userAlerts.displayMessage, { message: i18n(dataToRecover.successMessage)});
+ this.trigger(document, events.ui.userAlerts.displayMessage, { message: i18n.t(dataToRecover.successMessage)});
this.trigger(document, events.ui.mails.uncheckAll);
}, this);
};
@@ -136,7 +136,7 @@ define(
this.triggerArchived = function (dataToArchive) {
return _.bind(function (response) {
this.refreshMails();
- this.trigger(document, events.ui.userAlerts.displayMessage, { message: i18n(response.successMessage)});
+ this.trigger(document, events.ui.userAlerts.displayMessage, { message: i18n.t(response.successMessage)});
this.trigger(document, events.ui.mails.uncheckAll);
}, this);
};
@@ -151,14 +151,14 @@ define(
contentType: 'application/json; charset=utf-8',
data: JSON.stringify({idents: mailIdents})
}).done(this.triggerArchived(dataToArchive))
- .fail(this.errorMessage(i18n('Could not archive emails')));
+ .fail(this.errorMessage(i18n.t('Could not archive emails')));
};
this.deleteMail = function (ev, data) {
monitoredAjax(this, '/mail/' + data.mail.ident,
{type: 'DELETE'})
.done(this.triggerDeleted(data))
- .fail(this.errorMessage(i18n('Could not delete email')));
+ .fail(this.errorMessage(i18n.t('Could not delete email')));
};
this.deleteManyMails = function (ev, data) {
@@ -173,7 +173,7 @@ define(
contentType: 'application/json; charset=utf-8',
data: JSON.stringify({idents: mailIdents})
}).done(this.triggerDeleted(dataToDelete))
- .fail(this.errorMessage(i18n('Could not delete emails')));
+ .fail(this.errorMessage(i18n.t('Could not delete emails')));
};
this.recoverManyMails = function (ev, data) {
@@ -188,7 +188,7 @@ define(
contentType: 'application/json; charset=utf-8',
data: JSON.stringify({idents: mailIdents})
}).done(this.triggerRecovered(dataToRecover))
- .fail(this.errorMessage(i18n('Could not move emails to inbox')));
+ .fail(this.errorMessage(i18n.t('Could not move emails to inbox')));
};
function compileQuery(data) {
@@ -246,7 +246,7 @@ define(
this.trigger(document, events.mails.available, _.merge({tag: this.attr.currentTag, forSearch: this.attr.lastQuery }, this.parseMails(data)));
}.bind(this))
.fail(function () {
- this.trigger(document, events.ui.userAlerts.displayMessage, { message: i18n('Could not fetch messages'), class: 'error' });
+ this.trigger(document, events.ui.userAlerts.displayMessage, { message: i18n.t('Could not fetch messages'), class: 'error' });
}.bind(this));
};
diff --git a/web-ui/app/js/services/recover_service.js b/web-ui/app/js/services/recover_service.js
index 62fcf1f9..d7d9cdc9 100644
--- a/web-ui/app/js/services/recover_service.js
+++ b/web-ui/app/js/services/recover_service.js
@@ -25,7 +25,7 @@ define(['flight/lib/component', 'page/events', 'views/i18n'], function (defineCo
this.trigger(document, events.mail.recoverMany, {
mails: emails,
- successMessage: i18n('Your messages were moved to inbox!')
+ successMessage: i18n.t('Your messages were moved to inbox!')
});
};
diff --git a/web-ui/app/js/tags/ui/tag.js b/web-ui/app/js/tags/ui/tag.js
index ba6dfe61..37814cfc 100644
--- a/web-ui/app/js/tags/ui/tag.js
+++ b/web-ui/app/js/tags/ui/tag.js
@@ -78,7 +78,7 @@ define(
this.viewFor = function (tag, template, currentTag) {
return template({
- tagName: tag.default ? i18n('tags.' + tag.name) : tag.name,
+ tagName: tag.default ? i18n.t('tags.' + tag.name) : tag.name,
ident: this.hashIdent(tag.ident),
count: this.badgeType(tag) === 'total' ? tag.counts.total : (tag.counts.total - tag.counts.read),
displayBadge: this.displayBadge(tag),
diff --git a/web-ui/app/js/views/i18n.js b/web-ui/app/js/views/i18n.js
index 6a39ee89..f843b845 100644
--- a/web-ui/app/js/views/i18n.js
+++ b/web-ui/app/js/views/i18n.js
@@ -14,15 +14,49 @@
* You should have received a copy of the GNU Affero General Public License
* along with Pixelated. If not, see <http://www.gnu.org/licenses/>.
*/
-define(['i18next'], function(i18n) {
+define(['i18next',
+ 'i18nextXHRBackend',
+ 'i18nextBrowserLanguageDetector'],
+function(i18n, i18n_backend, I18n_detector) {
'use strict';
- var self = i18n.t;
+ var detector = new I18n_detector();
+ var detect = detector.detect.bind(detector);
- self.init = function(path) {
- i18n.init({detectLngQS: 'lang', fallbackLng: 'en_US', lowerCaseLng: true, getAsync: false, resGetPath: path + 'locales/__lng__/__ns__.json'});
- Handlebars.registerHelper('t', self.bind(self));
+ detector.detect = function(detectionOrder) {
+ var result = detect(detectionOrder);
+ return result.replace('-', '_');
};
- return self;
+ function t(i18n_key) {
+ var result = i18n.t(i18n_key);
+ var safe_string = new Handlebars.SafeString(result);
+ return safe_string.string;
+ }
+
+ function loaded(callback) {
+ i18n.on('loaded', function(loaded) {
+ callback();
+ });
+ }
+
+ function init(path) {
+ i18n
+ .use(i18n_backend)
+ .use(detector)
+ .init({
+ fallbackLng: 'en_US',
+ backend: {
+ loadPath: path + 'locales/{{lng}}/{{ns}}.json'
+ }
+ });
+ // Handlebars.registerHelper('t', self.bind(self));
+ Handlebars.registerHelper('t', t);
+ }
+
+ return {
+ t: t,
+ init: init,
+ loaded: loaded
+ };
});