File indexing completed on 2024-04-28 05:32:50

0001 /*
0002     Copyright (C) 2017 Kai Uwe Broulik <kde@privat.broulik.de>
0003 
0004     This program is free software; you can redistribute it and/or
0005     modify it under the terms of the GNU General Public License as
0006     published by the Free Software Foundation; either version 3 of
0007     the License, or (at your option) any later version.
0008 
0009     This program is distributed in the hope that it will be useful,
0010     but WITHOUT ANY WARRANTY; without even the implied warranty of
0011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0012     GNU General Public License for more details.
0013 
0014     You should have received a copy of the GNU General Public License
0015     along with this program.  If not, see <http://www.gnu.org/licenses/>.
0016  */
0017 
0018 document.addEventListener("DOMContentLoaded", function() {
0019 
0020     document.querySelectorAll("[data-i18n]").forEach(function (item) {
0021         var data = item.dataset.i18n.split(",").map(function (value) {
0022             value = value.trim();
0023 
0024             if (value.startsWith("__MSG_")) {
0025                 return value.replace(/__MSG_(\w+)__/g, function (match, key) {
0026                     return key ? chrome.i18n.getMessage(key) : "";
0027                 });
0028             }
0029 
0030             return value;
0031         });
0032 
0033         var text = chrome.i18n.getMessage(data.shift(), data) || ("I18N_UNKNOWN " + item.dataset.i18n);
0034 
0035         if (!!item.dataset.i18nHtml) {
0036             item.innerHTML = text;
0037         } else {
0038             item.innerText = text;
0039         }
0040     });
0041 
0042 });