MCPcopy
hub / github.com/1j01/jspaint / localize

Function localize

src/app-localization.js:17–47  ·  view source on GitHub ↗

* @param {string} english_text - The English text to localize * @param {...string} interpolations - Strings to replace %1, %2, etc. * @returns {string} - Text in the current language

(english_text, ...interpolations)

Source from the content-addressed store, hash-verified

15 * @returns {string} - Text in the current language
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]);
43 }
44 return text;
45 }
46 return interpolate(find_localization(english_text), interpolations);
47 }
48
49 const language_storage_key = "jspaint language";
50 // @ts-ignore

Callers 15

show_save_error_messageFunction · 0.85
$ToolBoxFunction · 0.85
show_recovery_windowFunction · 0.85
sessions.jsFile · 0.85
tools.jsFile · 0.85
pointerupFunction · 0.85
selectBoxFunction · 0.85
pointerdownFunction · 0.85
completeFunction · 0.85
set_languageFunction · 0.85
msgbox.jsFile · 0.85

Calls 2

interpolateFunction · 0.85
find_localizationFunction · 0.85

Tested by

no test coverage detected