aboutsummaryrefslogtreecommitdiffstats
path: root/js/i18n.js
diff options
context:
space:
mode:
authorJesús <heckyel@hyperbola.info>2019-12-30 15:55:13 -0500
committerJesús <heckyel@hyperbola.info>2019-12-30 15:55:13 -0500
commit288df6a7bf8b933e2dc499e38f4915fcf974c14b (patch)
tree77bba994f260c064d3ee7f76c427ddfaa4f91710 /js/i18n.js
parenta2c9deaa145b780722e93b3899600f287c8094a4 (diff)
downloadematrix-288df6a7bf8b933e2dc499e38f4915fcf974c14b.tar.lz
ematrix-288df6a7bf8b933e2dc499e38f4915fcf974c14b.tar.xz
ematrix-288df6a7bf8b933e2dc499e38f4915fcf974c14b.zip
backport
- Flush caches on upgrade - Properly handle FrameModule's unloading - Use the new module and remove the old implementation
Diffstat (limited to 'js/i18n.js')
-rw-r--r--js/i18n.js92
1 files changed, 46 insertions, 46 deletions
diff --git a/js/i18n.js b/js/i18n.js
index 3a6b0e2..7c377bb 100644
--- a/js/i18n.js
+++ b/js/i18n.js
@@ -43,13 +43,15 @@
// used to check the source text. The above comment is kept just
// in case.
- let reSafeTags = /^([\s\S]*?)<(b|blockquote|code|em|i|kbd|span|sup)>(.+?)<\/\2>([\s\S]*)$/;
+ let reSafeTags =
+ /^([\s\S]*?)<(b|blockquote|code|em|i|kbd|span|sup)>(.+?)<\/\2>([\s\S]*)$/;
let reSafeInput = /^([\s\S]*?)<(input type="[^"]+")>(.*?)([\s\S]*)$/;
let reInput = /^input type=(['"])([a-z]+)\1$/;
- let reSafeLink = /^([\s\S]*?)<(a href=['"]https?:\/\/[^'" <>]+['"])>(.+?)<\/a>([\s\S]*)$/;
+ let reSafeLink =
+ /^([\s\S]*?)<(a href=['"]https?:\/\/[^'" <>]+['"])>(.+?)<\/a>([\s\S]*)$/;
let reLink = /^a href=(['"])(https?:\/\/[^'"]+)\1$/;
- var safeTextToTagNode = function(text) {
+ let safeTextToTagNode = function (text) {
let matches;
let node;
@@ -96,7 +98,7 @@
}
};
- var safeTextToTextNode = function(text) {
+ let safeTextToTextNode = function (text) {
if (text.indexOf('&') !== -1) {
text = text
.replace(/&ldquo;/g, '“')
@@ -110,7 +112,7 @@
return document.createTextNode(text);
};
- var safeTextToDOM = function(text, parent) {
+ let safeTextToDOM = function (text, parent) {
if (text === '') {
return;
}
@@ -150,76 +152,74 @@
safeTextToDOM(matches[4], parent);
};
- /******************************************************************************/
-
// Helper to deal with the i18n'ing of HTML files.
- vAPI.i18n.render = function(context) {
- var docu = document,
- root = context || docu,
- elems, n, i, elem, text;
-
- elems = root.querySelectorAll('[data-i18n]');
- n = elems.length;
- for ( i = 0; i < n; i++ ) {
+ vAPI.i18n.render = function (context) {
+ let docu = document;
+ let root = context || docu;
+ let i, elem, text;
+
+ let elems = root.querySelectorAll('[data-i18n]');
+ let n = elems.length;
+ for (i=0; i<n; ++i) {
elem = elems[i];
text = vAPI.i18n(elem.getAttribute('data-i18n'));
- if ( !text ) { continue; }
+ if (!text) {
+ continue;
+ }
// TODO: remove once it's all replaced with <input type="...">
- if ( text.indexOf('{') !== -1 ) {
- text = text.replace(/\{\{input:([^}]+)\}\}/g, '<input type="$1">');
+ if (text.indexOf('{') !== -1) {
+ text =
+ text.replace(/\{\{input:([^}]+)\}\}/g, '<input type="$1">');
}
safeTextToDOM(text, elem);
}
- uDom('[title]', context).forEach(function(elem) {
- var title = vAPI.i18n(elem.attr('title'));
- if ( title ) {
+ uDom('[title]', context).forEach(function (elem) {
+ let title = vAPI.i18n(elem.attr('title'));
+ if (title) {
elem.attr('title', title);
}
});
- uDom('[placeholder]', context).forEach(function(elem) {
+ uDom('[placeholder]', context).forEach(function (elem) {
elem.attr('placeholder', vAPI.i18n(elem.attr('placeholder')));
});
- uDom('[data-i18n-tip]', context).forEach(function(elem) {
- elem.attr(
- 'data-tip',
- vAPI.i18n(elem.attr('data-i18n-tip'))
- .replace(/<br>/g, '\n')
- .replace(/\n{3,}/g, '\n\n')
- );
+ uDom('[data-i18n-tip]', context).forEach(function (elem) {
+ elem.attr('data-tip',
+ vAPI.i18n(elem.attr('data-i18n-tip'))
+ .replace(/<br>/g, '\n')
+ .replace(/\n{3,}/g, '\n\n'));
});
};
vAPI.i18n.render();
- /******************************************************************************/
-
- vAPI.i18n.renderElapsedTimeToString = function(tstamp) {
- var value = (Date.now() - tstamp) / 60000;
- if ( value < 2 ) {
+ vAPI.i18n.renderElapsedTimeToString = function (tstamp) {
+ let value = (Date.now() - tstamp) / 60000;
+ if (value < 2) {
return vAPI.i18n('elapsedOneMinuteAgo');
}
- if ( value < 60 ) {
- return vAPI.i18n('elapsedManyMinutesAgo').replace('{{value}}', Math.floor(value).toLocaleString());
+ if (value < 60) {
+ return vAPI
+ .i18n('elapsedManyMinutesAgo')
+ .replace('{{value}}', Math.floor(value).toLocaleString());
}
value /= 60;
- if ( value < 2 ) {
+ if (value < 2) {
return vAPI.i18n('elapsedOneHourAgo');
}
- if ( value < 24 ) {
- return vAPI.i18n('elapsedManyHoursAgo').replace('{{value}}', Math.floor(value).toLocaleString());
+ if (value < 24) {
+ return vAPI
+ .i18n('elapsedManyHoursAgo')
+ .replace('{{value}}', Math.floor(value).toLocaleString());
}
value /= 24;
- if ( value < 2 ) {
+ if (value < 2) {
return vAPI.i18n('elapsedOneDayAgo');
}
- return vAPI.i18n('elapsedManyDaysAgo').replace('{{value}}', Math.floor(value).toLocaleString());
+ return vAPI
+ .i18n('elapsedManyDaysAgo')
+ .replace('{{value}}', Math.floor(value).toLocaleString());
};
-
- /******************************************************************************/
-
})();
-
-/******************************************************************************/