From 288df6a7bf8b933e2dc499e38f4915fcf974c14b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs?= Date: Mon, 30 Dec 2019 15:55:13 -0500 Subject: backport - Flush caches on upgrade - Properly handle FrameModule's unloading - Use the new module and remove the old implementation --- js/i18n.js | 92 +++++++++++++++++++++++++++++++------------------------------- 1 file changed, 46 insertions(+), 46 deletions(-) (limited to 'js/i18n.js') 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(/“/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 - if ( text.indexOf('{') !== -1 ) { - text = text.replace(/\{\{input:([^}]+)\}\}/g, ''); + if (text.indexOf('{') !== -1) { + text = + text.replace(/\{\{input:([^}]+)\}\}/g, ''); } 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(/
/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(/
/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()); }; - - /******************************************************************************/ - })(); - -/******************************************************************************/ -- cgit v1.2.3