Adrià Vilanova MartÃnez | c14e44a | 2023-03-09 19:28:03 +0100 | [diff] [blame] | 1 | import MainWorldContentScriptBridgeServer from '../mainWorldContentScriptBridge/Server.js'; |
| 2 | |
| 3 | import {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). |
| 7 | export 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 | } |