ソースを参照

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.
JC Brand 9 年 前
コミット
9f9b38f852
6 ファイル変更35 行追加32 行削除
  1. 1 0
      src/converse-core.js
  2. 1 1
      src/converse-muc.js
  3. 15 12
      src/converse-otr.js
  4. 0 1
      src/converse-register.js
  5. 17 17
      src/locales.js
  6. 1 1
      src/utils.js

+ 1 - 0
src/converse-core.js

@@ -312,6 +312,7 @@
 
         // Translation machinery
         // ---------------------
+        this.i18n = settings.i18n ? settings.i18n : locales.en;
         var __ = utils.__.bind(this);
 
         // Default configuration values

+ 1 - 1
src/converse-muc.js

@@ -29,7 +29,7 @@
     // For translations
     var __ = utils.__.bind(converse);
     var ___ = utils.___;
-    
+
     // Add Strophe Namespaces
     Strophe.addNamespace('MUC_ADMIN', Strophe.NS.MUC + "#admin");
     Strophe.addNamespace('MUC_OWNER', Strophe.NS.MUC + "#owner");

+ 15 - 12
src/converse-otr.js

@@ -21,6 +21,9 @@
     var $ = converse_api.env.jQuery,
         _ = converse_api.env._;
 
+    // For translations
+    var __ = utils.__.bind(converse);
+
     var HAS_CSPRNG = ((typeof crypto !== 'undefined') &&
         ((typeof crypto.randomBytes === 'function') ||
             (typeof crypto.getRandomValues === 'function')
@@ -36,24 +39,13 @@
     var VERIFIED= 2;
     var FINISHED = 3;
 
-
+    var OTR_TRANSLATED_MAPPING  = {}; // Populated in initialize
     var OTR_CLASS_MAPPING = {};
     OTR_CLASS_MAPPING[UNENCRYPTED] = 'unencrypted';
     OTR_CLASS_MAPPING[UNVERIFIED] = 'unverified';
     OTR_CLASS_MAPPING[VERIFIED] = 'verified';
     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', {
 
         overrides: {
@@ -477,6 +469,17 @@
              * loaded by converse.js's plugin machinery.
              */
             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
             __ = utils.__.bind(converse);
             // Configuration values for this plugin

+ 0 - 1
src/converse-register.js

@@ -77,7 +77,6 @@
              */
             var converse = this.converse;
             // For translations
-            __ = utils.__.bind(converse);
             // Configuration values for this plugin
             var settings = {
                 allow_registration: true,

+ 17 - 17
src/locales.js

@@ -27,23 +27,23 @@
         'text!zh'
         ], function ($, Jed) {
             root.locales = {
-                'af':     arguments[2],
-                'de':     arguments[3],
-                'en':     arguments[4],
-                'es':     arguments[5],
-                'fr':     arguments[6],
-                'he':     arguments[7],
-                'hu':     arguments[8],
-                'id':     arguments[9],
-                'it':     arguments[10],
-                'ja':     arguments[11],
-                'nb':     arguments[12],
-                'nl':     arguments[13],
-                'pl':     arguments[14],
-                'pt-br':  arguments[15],
-                'ru':     arguments[16],
-                'uk':     arguments[17],
-                'zh':     arguments[18]
+                'af':     arguments[1],
+                'de':     arguments[2],
+                'en':     arguments[3],
+                'es':     arguments[4],
+                'fr':     arguments[5],
+                'he':     arguments[6],
+                'hu':     arguments[7],
+                'id':     arguments[8],
+                'it':     arguments[9],
+                'ja':     arguments[10],
+                'nb':     arguments[11],
+                'nl':     arguments[12],
+                'pl':     arguments[13],
+                'pt-br':  arguments[14],
+                'ru':     arguments[15],
+                'uk':     arguments[16],
+                'zh':     arguments[17]
             };
             return root.locales;
         });

+ 1 - 1
src/utils.js

@@ -1,4 +1,4 @@
-/*global escape locales */
+/*global escape, locales, Jed */
 (function (root, factory) {
     define([
         "jquery",