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

Function loadLanguage

src/js/language/Language.js:227–240  ·  view source on GitHub ↗

* Provide an async factory method for loading languages that clarifies the need to wait * for the language data to be loaded, so that other code doesn't press ahead before the language * is available. * * * @param {String} language_code - a language code or a fully-qualified URL to a langua

(language_code, script_path)

Source from the content-addressed store, hash-verified

225 * @returns {Language} - an instance of Language, or null if there's an error loading the translation file
226 */
227async function loadLanguage(language_code, script_path) {
228 var url = buildLanguageURL(language_code, script_path);
229 try {
230 if (!LANGUAGES[language_code]) {
231 let json = await fetchJSON(url)
232 LANGUAGES[language_code] = json
233 }
234 return new Language(language_code, script_path)
235 } catch (e) {
236 console.log(`Error loading language [${url}] ${e.statusText}`)
237 return null;
238 }
239
240}
241
242function buildLanguageURL(code, script_path) {
243 if (/\.json$/.test(code)) {

Callers 1

_loadLanguageMethod · 0.90

Calls 1

buildLanguageURLFunction · 0.85

Tested by

no test coverage detected