update readme
[dotfiles/.git] / .config / BraveSoftware / Brave-Browser / Default / Extensions / cimiefiiaegbelhefglklhhakcgmhkai / 1.7.6_0 / i18n.js
1 /*
2     Copyright (C) 2017 Kai Uwe Broulik <kde@privat.broulik.de>
3
4     This program is free software; you can redistribute it and/or
5     modify it under the terms of the GNU General Public License as
6     published by the Free Software Foundation; either version 3 of
7     the License, or (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17
18 document.addEventListener("DOMContentLoaded", function() {
19
20     document.querySelectorAll("[data-i18n]").forEach(function (item) {
21         var data = item.dataset.i18n.split(",").map(function (value) {
22             value = value.trim();
23
24             if (value.startsWith("__MSG_")) {
25                 return value.replace(/__MSG_(\w+)__/g, function (match, key) {
26                     return key ? chrome.i18n.getMessage(key) : "";
27                 });
28             }
29
30             return value;
31         });
32
33         var text = chrome.i18n.getMessage(data.shift(), data) || ("I18N_UNKNOWN " + item.dataset.i18n);
34
35         if (!!item.dataset.i18nHtml) {
36             item.innerHTML = text;
37         } else {
38             item.innerText = text;
39         }
40     });
41
42 });