Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: i18n.js

Issue 29569659: Issue 4580 - Replace ext.i18n.getMessage with i18n.getMessage (Closed) Base URL: https://hg.adblockplus.org/adblockplusui/
Patch Set: Rebase Created Oct. 9, 2017, 5:19 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« ext/common.js ('K') | « ext/common.js ('k') | lib/antiadblockInit.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: i18n.js
===================================================================
--- a/i18n.js
+++ b/i18n.js
@@ -12,61 +12,59 @@
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
*/
"use strict";
-// This variable should no longer be necessary once options.js in Chrome
-// accesses ext.i18n directly.
-let {i18n} = ext;
-
// Getting UI locale cannot be done synchronously on Firefox,
// requires messaging the background page. For Chrome and Safari,
// we could get the UI locale here, but would need to duplicate
// the logic implemented in Utils.appLocale.
ext.backgroundPage.sendMessage(
{
type: "app.get",
what: "localeInfo"
},
(localeInfo) =>
{
document.documentElement.lang = localeInfo.locale;
document.documentElement.dir = localeInfo.bidiDir;
}
);
-// Inserts i18n strings into matching elements. Any inner HTML already
-// in the element is parsed as JSON and used as parameters to
-// substitute into placeholders in the i18n message.
-ext.i18n.setElementText = function(element, stringName, args)
-{
- function processString(str, currentElement)
+ext.i18n = {
+ // Inserts i18n strings into matching elements. Any inner HTML already
+ // in the element is parsed as JSON and used as parameters to
+ // substitute into placeholders in the i18n message.
+ setElementText(element, stringName, args)
{
- let match = /^(.*?)<(a|strong)>(.*?)<\/\2>(.*)$/.exec(str);
- if (match)
+ function processString(str, currentElement)
{
- processString(match[1], currentElement);
+ let match = /^(.*?)<(a|strong)>(.*?)<\/\2>(.*)$/.exec(str);
+ if (match)
+ {
+ processString(match[1], currentElement);
- let e = document.createElement(match[2]);
- processString(match[3], e);
- currentElement.appendChild(e);
+ let e = document.createElement(match[2]);
+ processString(match[3], e);
+ currentElement.appendChild(e);
- processString(match[4], currentElement);
+ processString(match[4], currentElement);
+ }
+ else
+ currentElement.appendChild(document.createTextNode(str));
}
- else
- currentElement.appendChild(document.createTextNode(str));
+
+ while (element.lastChild)
+ element.removeChild(element.lastChild);
+ processString(chrome.i18n.getMessage(stringName, args), element);
}
-
- while (element.lastChild)
- element.removeChild(element.lastChild);
- processString(ext.i18n.getMessage(stringName, args), element);
};
// Loads i18n strings
function loadI18nStrings()
{
function addI18nStringsToElements(containerElement)
{
let elements = containerElement.querySelectorAll("[class^='i18n_']");
« ext/common.js ('K') | « ext/common.js ('k') | lib/antiadblockInit.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld