MCPcopy
hub / github.com/NUKnightLab/TimelineJS3 / constructor

Method constructor

src/js/language/Language.js:20–39  ·  view source on GitHub ↗
(language, script_path)

Source from the content-addressed store, hash-verified

18 */
19class Language {
20 constructor(language, script_path) {
21 // borrowed from http://stackoverflow.com/a/14446414/102476
22 for (let k in LANGUAGES.en) {
23 this[k] = LANGUAGES.en[k];
24 }
25 // `language` won't be defined when the fallback is constructed
26 if (language && typeof(language) == 'string' && language != 'en') {
27 var code = language;
28 if (!(code in LANGUAGES)) {
29 console.log(`Expected language ${code} to be cached. Did you call the constructor directly?`)
30 var url = buildLanguageURL(code, script_path);
31 fetchJSON(url).then((json) => {
32 LANGUAGES[code] = json
33 }).catch(resp => {
34 console.log(`Error loading language [${url}] ${resp.statusText} [${resp.status}]`)
35 })
36 }
37 mergeData(this, LANGUAGES[code]);
38 }
39 }
40
41 /**
42 * Reimplement Util.mergeData to handle nested dictionaries

Callers

nothing calls this directly

Calls 2

mergeDataFunction · 0.90
buildLanguageURLFunction · 0.85

Tested by

no test coverage detected