| 16 | */ |
| 17 | function localize(english_text, ...interpolations) { |
| 18 | function find_localization(english_text) { |
| 19 | if (AccessKeys.has(english_text)) { |
| 20 | const without_hotkey = AccessKeys.remove(english_text); |
| 21 | if (localizations[without_hotkey]) { |
| 22 | const hotkey_def = AccessKeys.get(english_text); |
| 23 | if (localizations[without_hotkey].toUpperCase().indexOf(hotkey_def.toUpperCase()) > -1) { |
| 24 | return localizations[without_hotkey]; |
| 25 | } else { |
| 26 | if (AccessKeys.has(localizations[without_hotkey])) { |
| 27 | // window.console?.warn(`Localization has differing access key hint: '${localizations[without_hotkey]}' vs '${english_text}'`); |
| 28 | // @TODO: detect differing access key more generally |
| 29 | return `${AccessKeys.remove(localizations[without_hotkey])} (${hotkey_def})`; |
| 30 | } |
| 31 | return `${localizations[without_hotkey]} (${hotkey_def})`; |
| 32 | } |
| 33 | } |
| 34 | } |
| 35 | if (localizations[english_text]) { |
| 36 | return localizations[english_text]; |
| 37 | } |
| 38 | return english_text; |
| 39 | } |
| 40 | function interpolate(text, interpolations) { |
| 41 | for (let i = 0; i < interpolations.length; i++) { |
| 42 | text = text.replace(`%${i + 1}`, interpolations[i]); |