diff --git a/converse.js b/converse.js index 5fa6bd217..b2f741960 100644 --- a/converse.js +++ b/converse.js @@ -12,19 +12,34 @@ define("converse", ["converse-dependencies", "converse-templates"], function (dependencies, templates) { - var otr = dependencies.otr, - moment = dependencies.moment; + var otr = dependencies.otr; if (typeof otr !== "undefined") { - return factory(dependencies.jQuery, _, otr.OTR, otr.DSA, templates, moment); + return factory( + dependencies.jQuery, + _, + otr.OTR, + otr.DSA, + templates, + dependencies.moment, + dependencies.utils + ); } else { - return factory(dependencies.jQuery, _, undefined, undefined, templates, moment); + return factory( + dependencies.jQuery, + _, + undefined, + undefined, + templates, + dependencies.moment, + dependencies.utils + ); } } ); } else { - root.converse = factory(jQuery, _, OTR, DSA, JST, moment); + root.converse = factory(jQuery, _, OTR, DSA, JST, moment, utils); } -}(this, function ($, _, OTR, DSA, templates, moment) { +}(this, function ($, _, OTR, DSA, templates, moment, utils) { // "use strict"; // Cannot use this due to Safari bug. // See https://github.com/jcbrand/converse.js/issues/196 @@ -297,30 +312,8 @@ // Translation machinery // --------------------- - var __ = $.proxy(function (str) { - // Translation factory - if (this.i18n === undefined) { - this.i18n = locales.en; - } - var t = this.i18n.translate(str); - if (arguments.length>1) { - return t.fetch.apply(t, [].slice.call(arguments,1)); - } else { - return t.fetch(); - } - }, this); - - var ___ = function (str) { - /* XXX: This is part of a hack to get gettext to scan strings to be - * translated. Strings we cannot send to the function above because - * they require variable interpolation and we don't yet have the - * variables at scan time. - * - * See actionInfoMessages - */ - return str; - }; - + var __ = utils.__; + var ___ = utils.___; // Translation aware constants // --------------------------- var OTR_CLASS_MAPPING = {}; @@ -1100,7 +1093,6 @@ // are mentioned. extra_classes += ' mentioned'; } - var message = template({ 'sender': msg_dict.sender, 'time': msg_time.format('hh:mm'), @@ -4626,7 +4618,7 @@ this._initializePlugins = function () { _.each(this.plugins, $.proxy(function (plugin) { - $.proxy(plugin, this)(); + $.proxy(plugin, this)(this); }, this)); }; diff --git a/src/deps-full.js b/src/deps-full.js index 930bb2ce1..1e2a71b70 100644 --- a/src/deps-full.js +++ b/src/deps-full.js @@ -1,5 +1,6 @@ define("converse-dependencies", [ "jquery", + "utils", "otr", "moment", "locales", @@ -7,16 +8,16 @@ define("converse-dependencies", [ "backbone.overview", "jquery.browser", "typeahead", - "utils", "strophe", "strophe.muc", "strophe.roster", "strophe.vcard", "strophe.disco" -], function($, otr, moment) { +], function($, utils, otr, moment) { return { 'jQuery': $, + 'moment': moment, 'otr': otr, - 'moment': moment + 'utils': utils }; }); diff --git a/src/deps-no-otr.js b/src/deps-no-otr.js index c72e6a7fe..f7fb61ebd 100644 --- a/src/deps-no-otr.js +++ b/src/deps-no-otr.js @@ -1,21 +1,22 @@ define("converse-dependencies", [ "jquery", + "utils", "moment", "locales", "backbone.browserStorage", "backbone.overview", "jquery.browser", "typeahead", - "utils", "strophe", "strophe.muc", "strophe.roster", "strophe.vcard", "strophe.disco" -], function($, moment) { +], function($, utils, moment) { return { 'jQuery': $, 'otr': undefined, - 'moment': moment + 'moment': moment, + 'utils': utils }; }); diff --git a/src/deps-website-no-otr.js b/src/deps-website-no-otr.js index f8fab79da..f3712f428 100644 --- a/src/deps-website-no-otr.js +++ b/src/deps-website-no-otr.js @@ -1,5 +1,6 @@ define("converse-dependencies", [ "jquery", + "utils", "moment", "locales", "bootstrapJS", // XXX: Can be removed, only for https://conversejs.org @@ -8,16 +9,16 @@ define("converse-dependencies", [ "jquery.browser", "jquery.easing", // XXX: Can be removed, only for https://conversejs.org "typeahead", - "utils", "strophe", "strophe.muc", "strophe.roster", "strophe.vcard", "strophe.disco" -], function($, moment) { +], function($, utils, moment) { return { 'jQuery': $, 'otr': undefined, - 'moment': moment + 'moment': moment, + 'utils': utils }; }); diff --git a/src/deps-website.js b/src/deps-website.js index bbbf4b894..def8fe87c 100644 --- a/src/deps-website.js +++ b/src/deps-website.js @@ -1,5 +1,6 @@ define("converse-dependencies", [ "jquery", + "utils", "otr", "moment", "locales", @@ -9,16 +10,16 @@ define("converse-dependencies", [ "jquery.browser", "jquery.easing", // XXX: Only for https://conversejs.org "typeahead", - "utils", "strophe", "strophe.muc", "strophe.roster", "strophe.vcard", "strophe.disco" -], function($, otr, moment) { +], function($, utils, otr, moment) { return { 'jQuery': $, 'otr': otr, - 'moment': moment + 'moment': moment, + 'utils': utils }; }); diff --git a/src/utils.js b/src/utils.js index 94f9f15b8..61716d902 100644 --- a/src/utils.js +++ b/src/utils.js @@ -26,4 +26,33 @@ define(["jquery"], function ($) { } return this; }; + + var utils = { + // Translation machinery + // --------------------- + __: $.proxy(function (str) { + // Translation factory + if (this.i18n === undefined) { + this.i18n = locales.en; + } + var t = this.i18n.translate(str); + if (arguments.length>1) { + return t.fetch.apply(t, [].slice.call(arguments,1)); + } else { + return t.fetch(); + } + }, this), + + ___: function (str) { + /* XXX: This is part of a hack to get gettext to scan strings to be + * translated. Strings we cannot send to the function above because + * they require variable interpolation and we don't yet have the + * variables at scan time. + * + * See actionInfoMessages + */ + return str; + } + }; + return utils; });