Move translation factory to utils

So that it can be used by plugins.
This commit is contained in:
JC Brand 2014-10-13 22:02:55 +02:00
parent 970da2acf0
commit 55c57a346d
6 changed files with 69 additions and 44 deletions

View File

@ -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));
};

View File

@ -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
};
});

View File

@ -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
};
});

View File

@ -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
};
});

View File

@ -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
};
});

View File

@ -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;
});