1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/addon-sdk/source/lib/sdk/l10n/prefs.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,42 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 +"use strict"; 1.8 + 1.9 +const { on } = require("../system/events"); 1.10 +const core = require("./core"); 1.11 +const { id: jetpackId} = require('../self'); 1.12 + 1.13 +const OPTIONS_DISPLAYED = "addon-options-displayed"; 1.14 + 1.15 +function onOptionsDisplayed({ subject: document, data: addonId }) { 1.16 + if (addonId !== jetpackId) 1.17 + return; 1.18 + let query = 'setting[data-jetpack-id="' + jetpackId + '"][pref-name], ' + 1.19 + 'button[data-jetpack-id="' + jetpackId + '"][pref-name]'; 1.20 + let nodes = document.querySelectorAll(query); 1.21 + for (let node of nodes) { 1.22 + let name = node.getAttribute("pref-name"); 1.23 + if (node.tagName == "setting") { 1.24 + let desc = core.get(name + "_description"); 1.25 + if (desc) 1.26 + node.setAttribute("desc", desc); 1.27 + let title = core.get(name + "_title"); 1.28 + if (title) 1.29 + node.setAttribute("title", title); 1.30 + 1.31 + for (let item of node.querySelectorAll("menuitem, radio")) { 1.32 + let key = name + "_options." + item.getAttribute("label"); 1.33 + let label = core.get(key); 1.34 + if (label) 1.35 + item.setAttribute("label", label); 1.36 + } 1.37 + } 1.38 + else if (node.tagName == "button") { 1.39 + let label = core.get(name + "_label"); 1.40 + if (label) 1.41 + node.setAttribute("label", label); 1.42 + } 1.43 + } 1.44 +} 1.45 +on(OPTIONS_DISPLAYED, onOptionsDisplayed);