 Issue 29569659:
  Issue 4580 - Replace ext.i18n.getMessage with i18n.getMessage  (Closed) 
  Base URL: https://hg.adblockplus.org/adblockplusui/
    
  
    Issue 29569659:
  Issue 4580 - Replace ext.i18n.getMessage with i18n.getMessage  (Closed) 
  Base URL: https://hg.adblockplus.org/adblockplusui/| 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; | 
| 
Manish Jethani
2017/10/09 05:10:14
This is no longer necessary because of the other c
 | 
| - | 
| // 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) | 
| 
Manish Jethani
2017/10/09 05:10:14
Leaving setElementText here instead of sticking it
 | 
| { | 
| - 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_']"); |