mirror of
https://gitlab.com/timvisee/send.git
synced 2025-12-07 06:30:53 +03:00
encapsulate translate function creation
This commit is contained in:
@@ -42,14 +42,15 @@ if (typeof window === 'undefined') {
|
|||||||
require('babel-polyfill');
|
require('babel-polyfill');
|
||||||
var fluent = require('fluent/compat');
|
var fluent = require('fluent/compat');
|
||||||
}
|
}
|
||||||
var fluentContext = new fluent.MessageContext('${locale}', {useIsolating: false});
|
(function () {
|
||||||
fluentContext._messages = new Map(${toJSON(merged)});
|
var ctx = new fluent.MessageContext('${locale}', {useIsolating: false});
|
||||||
|
ctx._messages = new Map(${toJSON(merged)});
|
||||||
function translate(id, data) {
|
function translate(id, data) {
|
||||||
var msg = fluentContext.getMessage(id);
|
var msg = ctx.getMessage(id);
|
||||||
if (typeof(msg) !== 'string' && !msg.val && msg.attrs) {
|
if (typeof(msg) !== 'string' && !msg.val && msg.attrs) {
|
||||||
msg = msg.attrs.title || msg.attrs.alt
|
msg = msg.attrs.title || msg.attrs.alt
|
||||||
}
|
}
|
||||||
return fluentContext.format(msg, data);
|
return ctx.format(msg, data);
|
||||||
}
|
}
|
||||||
if (typeof window === 'undefined') {
|
if (typeof window === 'undefined') {
|
||||||
module.exports = translate;
|
module.exports = translate;
|
||||||
@@ -57,5 +58,6 @@ if (typeof window === 'undefined') {
|
|||||||
else {
|
else {
|
||||||
window.translate = translate;
|
window.translate = translate;
|
||||||
}
|
}
|
||||||
|
})();
|
||||||
\``;
|
\``;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user