blob: 7299ee9fb7aff2e969fba96d20c36fbda2bd0a92 [file] [log] [blame]
Adrià Vilanova Martínezc14e44a2023-03-09 19:28:03 +01001import MainWorldContentScriptBridgeServer from '../mainWorldContentScriptBridge/Server.js';
2
3import {kCSTarget, kMWTarget} from './consts.js';
4
5// Main World i18n server (used in content scripts to be able to serve the
6// chrome.i18n API to Main World (MW) scripts).
7export default class MWI18nServer extends MainWorldContentScriptBridgeServer {
8 constructor() {
9 super(kCSTarget, kMWTarget);
10 this.setUpHandler(this.handleMessage);
11 }
12
13 handleMessage(uuid, action, request) {
14 switch (action) {
15 case 'getMessage':
16 var response = chrome.i18n.getMessage(
17 request.messageName, request.substitutions, request.options);
18 this._respond(uuid, response);
19 return;
20
21 case 'getUILanguage':
22 this._respond(uuid, chrome.i18n.getUILanguage());
23 return;
24
25 default:
26 console.error(`[MWI18nServer] Invalid action received (${action})`);
27 }
28 }
29}