Commit 9f9b38f8 authored by JC Brand's avatar JC Brand

Some i18n fixes

The __ translate method should only be run *after* converse.js has been
initialized and we know what the actual desired language is

Also fix bug in src/locales.js where wrong langs were assigned to wrong keys.
parent c370b3e9
...@@ -312,6 +312,7 @@ ...@@ -312,6 +312,7 @@
// Translation machinery // Translation machinery
// --------------------- // ---------------------
this.i18n = settings.i18n ? settings.i18n : locales.en;
var __ = utils.__.bind(this); var __ = utils.__.bind(this);
// Default configuration values // Default configuration values
......
...@@ -21,6 +21,9 @@ ...@@ -21,6 +21,9 @@
var $ = converse_api.env.jQuery, var $ = converse_api.env.jQuery,
_ = converse_api.env._; _ = converse_api.env._;
// For translations
var __ = utils.__.bind(converse);
var HAS_CSPRNG = ((typeof crypto !== 'undefined') && var HAS_CSPRNG = ((typeof crypto !== 'undefined') &&
((typeof crypto.randomBytes === 'function') || ((typeof crypto.randomBytes === 'function') ||
(typeof crypto.getRandomValues === 'function') (typeof crypto.getRandomValues === 'function')
...@@ -36,24 +39,13 @@ ...@@ -36,24 +39,13 @@
var VERIFIED= 2; var VERIFIED= 2;
var FINISHED = 3; var FINISHED = 3;
var OTR_TRANSLATED_MAPPING = {}; // Populated in initialize
var OTR_CLASS_MAPPING = {}; var OTR_CLASS_MAPPING = {};
OTR_CLASS_MAPPING[UNENCRYPTED] = 'unencrypted'; OTR_CLASS_MAPPING[UNENCRYPTED] = 'unencrypted';
OTR_CLASS_MAPPING[UNVERIFIED] = 'unverified'; OTR_CLASS_MAPPING[UNVERIFIED] = 'unverified';
OTR_CLASS_MAPPING[VERIFIED] = 'verified'; OTR_CLASS_MAPPING[VERIFIED] = 'verified';
OTR_CLASS_MAPPING[FINISHED] = 'finished'; OTR_CLASS_MAPPING[FINISHED] = 'finished';
// Translation aware constants
// ---------------------------
var __ = utils.__.bind(converse);
var OTR_TRANSLATED_MAPPING = {};
OTR_TRANSLATED_MAPPING[UNENCRYPTED] = __('unencrypted');
OTR_TRANSLATED_MAPPING[UNVERIFIED] = __('unverified');
OTR_TRANSLATED_MAPPING[VERIFIED] = __('verified');
OTR_TRANSLATED_MAPPING[FINISHED] = __('finished');
converse_api.plugins.add('otr', { converse_api.plugins.add('otr', {
overrides: { overrides: {
...@@ -477,6 +469,17 @@ ...@@ -477,6 +469,17 @@
* loaded by converse.js's plugin machinery. * loaded by converse.js's plugin machinery.
*/ */
var converse = this.converse; var converse = this.converse;
// Translation aware constants
// ---------------------------
// We can only call the __ translation method *after* converse.js
// has been initialized and with it the i18n machinery. That's why
// we do it here in the "initialize" method and not at the top of
// the module.
OTR_TRANSLATED_MAPPING[UNENCRYPTED] = __('unencrypted');
OTR_TRANSLATED_MAPPING[UNVERIFIED] = __('unverified');
OTR_TRANSLATED_MAPPING[VERIFIED] = __('verified');
OTR_TRANSLATED_MAPPING[FINISHED] = __('finished');
// For translations // For translations
__ = utils.__.bind(converse); __ = utils.__.bind(converse);
// Configuration values for this plugin // Configuration values for this plugin
......
...@@ -77,7 +77,6 @@ ...@@ -77,7 +77,6 @@
*/ */
var converse = this.converse; var converse = this.converse;
// For translations // For translations
__ = utils.__.bind(converse);
// Configuration values for this plugin // Configuration values for this plugin
var settings = { var settings = {
allow_registration: true, allow_registration: true,
......
...@@ -27,23 +27,23 @@ ...@@ -27,23 +27,23 @@
'text!zh' 'text!zh'
], function ($, Jed) { ], function ($, Jed) {
root.locales = { root.locales = {
'af': arguments[2], 'af': arguments[1],
'de': arguments[3], 'de': arguments[2],
'en': arguments[4], 'en': arguments[3],
'es': arguments[5], 'es': arguments[4],
'fr': arguments[6], 'fr': arguments[5],
'he': arguments[7], 'he': arguments[6],
'hu': arguments[8], 'hu': arguments[7],
'id': arguments[9], 'id': arguments[8],
'it': arguments[10], 'it': arguments[9],
'ja': arguments[11], 'ja': arguments[10],
'nb': arguments[12], 'nb': arguments[11],
'nl': arguments[13], 'nl': arguments[12],
'pl': arguments[14], 'pl': arguments[13],
'pt-br': arguments[15], 'pt-br': arguments[14],
'ru': arguments[16], 'ru': arguments[15],
'uk': arguments[17], 'uk': arguments[16],
'zh': arguments[18] 'zh': arguments[17]
}; };
return root.locales; return root.locales;
}); });
......
/*global escape locales */ /*global escape, locales, Jed */
(function (root, factory) { (function (root, factory) {
define([ define([
"jquery", "jquery",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment