MCPcopy Create free account
hub / github.com/Monogatari/Monogatari / localize

Function localize

src/engine/i18n.ts:42–69  ·  view source on GitHub ↗
(engine: VisualNovelEngine)

Source from the content-addressed store, hash-verified

40}
41
42export function localize (engine: VisualNovelEngine): void {
43 engine.trigger ('willLocalize');
44
45 // Setup the correct locale for the dates
46 const language = engine.preference ('Language') as string;
47
48 const langMetadata = engine._languageMetadata[language];
49
50 if (langMetadata?.code) {
51 Settings.defaultLocale = langMetadata.code;
52 }
53
54 engine.element ().find ('[data-string]').each ((element) => {
55 const stringKey = $_(element).data ('string');
56
57 if (stringKey) {
58 const string_translation = translateString (engine, stringKey);
59
60 // Check if the translation actually exists and is not empty before
61 // replacing the text.
62 if (typeof string_translation !== 'undefined' && string_translation !== '') {
63 $_(element).text (string_translation);
64 }
65 }
66 });
67
68 engine.trigger ('didLocalize');
69}
70
71/**
72 * This method will try to translate parts of a string

Callers

nothing calls this directly

Calls 5

translateStringFunction · 0.85
triggerMethod · 0.80
preferenceMethod · 0.80
eachMethod · 0.65
elementMethod · 0.45

Tested by

no test coverage detected