electron/spec/fixtures/extensions/chrome-i18n/v3/main.js

37 lines
932 B
JavaScript

/* global chrome */
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
sendResponse(request);
});
const map = {
getAcceptLanguages () {
chrome.i18n.getAcceptLanguages().then((languages) => {
console.log(JSON.stringify(languages));
});
},
getMessage () {
const message = chrome.i18n.getMessage('extName');
console.log(JSON.stringify(message));
},
getUILanguage () {
const language = chrome.i18n.getUILanguage();
console.log(JSON.stringify(language));
},
async detectLanguage (texts) {
const result = [];
for (const text of texts) {
const language = await chrome.i18n.detectLanguage(text);
result.push(language);
}
console.log(JSON.stringify(result));
}
};
const dispatchTest = (event) => {
const { method, args = [] } = JSON.parse(event.data);
map[method](...args);
};
window.addEventListener('message', dispatchTest, false);