From 4fb2d879ec034bb10455abef2983907ea7e28c84 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Sat, 4 Nov 2017 23:35:46 -0400 Subject: [PATCH] fetch edge messages --- src/services/i18nService.js | 31 +++++++++++-------------------- 1 file changed, 11 insertions(+), 20 deletions(-) diff --git a/src/services/i18nService.js b/src/services/i18nService.js index 7ffc90c8..3079c6e1 100644 --- a/src/services/i18nService.js +++ b/src/services/i18nService.js @@ -1,27 +1,18 @@ export default function i18nService(utilsService) { - this.utilsService = utilsService; - this.messages = {}; - - var self = this; - - if (self.utilsService.isEdge()) { - var rawFile = new XMLHttpRequest(); - rawFile.open('GET', '../_locales/en/messages.json', false); - rawFile.onreadystatechange = function () { - if (rawFile.readyState === 4) { - if (rawFile.status === 200 || rawFile.status === 0) { - var locales = JSON.parse(rawFile.responseText); - for (var property in locales) { - if (locales.hasOwnProperty(property)) { - self.messages[property] = chrome.i18n.getMessage(property); - } - } + if (utilsService.isEdge()) { + this.__edgeMessages = {}; + const self = this; + fetch('../_locales/en/messages.json').then((file) => { + return file.json(); + }).then((locales) => { + for (const prop in locales) { + if (locales.hasOwnProperty(prop)) { + self.__edgeMessages[prop] = chrome.i18n.getMessage(prop); } } - }; - rawFile.send(null); + }); - return self.messages; + return this.__edgeMessages; } return new Proxy({}, {