| 51 | |
| 52 | // Function to get a message (from custom locale or chrome.i18n) |
| 53 | function getMessage(key, substitutions) { |
| 54 | // If we have custom locale messages and the key exists, use it |
| 55 | if (customLocaleMessages && customLocaleMessages[key]) { |
| 56 | let message = customLocaleMessages[key].message; |
| 57 | // Handle substitutions if provided |
| 58 | if (substitutions) { |
| 59 | const subs = Array.isArray(substitutions) ? substitutions : [substitutions]; |
| 60 | subs.forEach((sub, index) => { |
| 61 | message = message.replace(`$${index + 1}`, sub); |
| 62 | }); |
| 63 | } |
| 64 | return message; |
| 65 | } |
| 66 | // Otherwise, use chrome.i18n.getMessage |
| 67 | return chrome.i18n.getMessage(key, substitutions); |
| 68 | } |
| 69 | |
| 70 | // Load all i18n text |
| 71 | function loadI18nText() { |