Quellcode durchsuchen

Lazily call parseJSON on translation data.

Also, moved locales.js to ./src folder.
Add it as dependency to utils.js and remove it from the deps scripts
JC Brand vor 10 Jahren
Ursprung
Commit
8478b432c3
10 geänderte Dateien mit 52 neuen und 22 gelöschten Zeilen
  1. 1 3
      converse.js
  2. 0 1
      dev.html
  3. 0 12
      locale/locales.js
  4. 1 1
      main.js
  5. 0 1
      src/deps-full.js
  6. 0 1
      src/deps-no-otr.js
  7. 0 1
      src/deps-website-no-otr.js
  8. 0 1
      src/deps-website.js
  9. 46 0
      src/locales.js
  10. 4 1
      src/utils.js

+ 1 - 3
converse.js

@@ -225,6 +225,7 @@
 
 
         // Translation machinery
         // Translation machinery
         // ---------------------
         // ---------------------
+        this.i18n = settings.i18n ? settings.i18n : locales.en;
         var __ = $.proxy(utils.__, this);
         var __ = $.proxy(utils.__, this);
         var ___ = utils.___;
         var ___ = utils.___;
 
 
@@ -250,7 +251,6 @@
             forward_messages: false,
             forward_messages: false,
             hide_muc_server: false,
             hide_muc_server: false,
             hide_offline_users: false,
             hide_offline_users: false,
-            i18n: locales.en,
             jid: undefined,
             jid: undefined,
             keepalive: false,
             keepalive: false,
             message_carbons: false,
             message_carbons: false,
@@ -282,8 +282,6 @@
         // Allow only whitelisted configuration attributes to be overwritten
         // Allow only whitelisted configuration attributes to be overwritten
         _.extend(this, _.pick(settings, Object.keys(default_settings)));
         _.extend(this, _.pick(settings, Object.keys(default_settings)));
 
 
-        this.jed = new Jed(this.i18n);
-
         if (settings.visible_toolbar_buttons) {
         if (settings.visible_toolbar_buttons) {
             _.extend(
             _.extend(
                 this.visible_toolbar_buttons,
                 this.visible_toolbar_buttons,

+ 0 - 1
dev.html

@@ -17,7 +17,6 @@
 </head>
 </head>
 
 
 <body id="page-top" data-spy="scroll" data-target=".navbar-custom">
 <body id="page-top" data-spy="scroll" data-target=".navbar-custom">
-
     <nav class="navbar navbar-custom navbar-fixed-top" role="navigation">
     <nav class="navbar navbar-custom navbar-fixed-top" role="navigation">
         <div class="container">
         <div class="container">
             <div class="navbar-header page-scroll">
             <div class="navbar-header page-scroll">

+ 0 - 12
locale/locales.js

@@ -1,12 +0,0 @@
-/*
- * This file specifies the language dependencies.
- *
- * Translations take up a lot of space and you are therefore advised to remove
- * from here any languages that you don't need.
- */
-
-(function (root, factory) {
-    define("locales", ['jquery', 'jed', 
-        ], function ($, Jed, af, de, en, es, fr, he, hu, id, it, ja, nb, nl, pl, pt_BR, ru, zh) {
-        });
-})(this);

+ 1 - 1
main.js

@@ -56,7 +56,7 @@ require.config({
         "otr":                  "src/otr",
         "otr":                  "src/otr",
 
 
         // Locales paths
         // Locales paths
-        "locales":   "locale/locales",
+        "locales":   "src/locales",
         "jed":       "components/jed/jed",
         "jed":       "components/jed/jed",
         "af":        "locale/af/LC_MESSAGES/converse.json",
         "af":        "locale/af/LC_MESSAGES/converse.json",
         "de":        "locale/de/LC_MESSAGES/converse.json",
         "de":        "locale/de/LC_MESSAGES/converse.json",

+ 0 - 1
src/deps-full.js

@@ -3,7 +3,6 @@ define("converse-dependencies", [
     "utils",
     "utils",
     "otr",
     "otr",
     "moment",
     "moment",
-    "locales",
     "backbone.browserStorage",
     "backbone.browserStorage",
     "backbone.overview",
     "backbone.overview",
     "jquery.browser",
     "jquery.browser",

+ 0 - 1
src/deps-no-otr.js

@@ -2,7 +2,6 @@ define("converse-dependencies", [
     "jquery",
     "jquery",
     "utils",
     "utils",
     "moment",
     "moment",
-    "locales",
     "backbone.browserStorage",
     "backbone.browserStorage",
     "backbone.overview",
     "backbone.overview",
     "jquery.browser",
     "jquery.browser",

+ 0 - 1
src/deps-website-no-otr.js

@@ -2,7 +2,6 @@ define("converse-dependencies", [
     "jquery",
     "jquery",
     "utils",
     "utils",
     "moment",
     "moment",
-    "locales",
     "bootstrapJS", // XXX: Can be removed, only for https://conversejs.org
     "bootstrapJS", // XXX: Can be removed, only for https://conversejs.org
     "backbone.browserStorage",
     "backbone.browserStorage",
     "backbone.overview",
     "backbone.overview",

+ 0 - 1
src/deps-website.js

@@ -3,7 +3,6 @@ define("converse-dependencies", [
     "utils",
     "utils",
     "otr",
     "otr",
     "moment",
     "moment",
-    "locales",
     "bootstrapJS", // XXX: Only for https://conversejs.org
     "bootstrapJS", // XXX: Only for https://conversejs.org
     "backbone.browserStorage",
     "backbone.browserStorage",
     "backbone.overview",
     "backbone.overview",

+ 46 - 0
src/locales.js

@@ -0,0 +1,46 @@
+/*
+ * This file specifies the language dependencies.
+ *
+ * Translations take up a lot of space and you are therefore advised to remove
+ * from here any languages that you don't need.
+ */
+(function (root, factory) {
+    define("locales", ['jquery', 'jed', 
+        'text!af',
+        'text!de',
+        'text!en',
+        'text!es',
+        'text!fr',
+        'text!he',
+        'text!hu',
+        'text!id',
+        'text!it',
+        'text!ja',
+        'text!nb',
+        'text!nl',
+        'text!pl',
+        'text!pt_BR',
+        'text!ru',
+        '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],
+                'zh':     arguments[17]
+            };
+            return root.locales;
+        });
+})(this);

+ 4 - 1
src/utils.js

@@ -4,7 +4,7 @@
     } else {
     } else {
         root.utils = factory(jQuery, templates);
         root.utils = factory(jQuery, templates);
     }
     }
-}(this, function ($, templates) {
+}(this, function ($, templates, locales) {
     "use strict";
     "use strict";
 
 
     var XFORM_TYPE_MAP = {
     var XFORM_TYPE_MAP = {
@@ -58,6 +58,9 @@
             if (typeof this.i18n === "undefined") {
             if (typeof this.i18n === "undefined") {
                 this.i18n = locales.en;
                 this.i18n = locales.en;
             }
             }
+            if (typeof this.i18n === "string") {
+                this.i18n = $.parseJSON(this.i18n);
+            }
             if (typeof this.jed === "undefined") {
             if (typeof this.jed === "undefined") {
                 this.jed = new Jed(this.i18n);
                 this.jed = new Jed(this.i18n);
             }
             }