forked from sugarlabs/musicblocks
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathloader.js
More file actions
104 lines (93 loc) · 3.17 KB
/
loader.js
File metadata and controls
104 lines (93 loc) · 3.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
// Copyright (c) 2015-2024 Yash Khandelwal
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the The GNU Affero General Public
// License as published by the Free Software Foundation; either
// version 3 of the License, or (at your option) any later version.
//
// You should have received a copy of the GNU Affero General Public
// License along with this library; if not, write to the Free Software
// Foundation, 51 Franklin Street, Suite 500 Boston, MA 02110-1335 USA
/* global requirejs */
requirejs.config({
baseUrl: "lib",
shim: {
easel: {
exports: "createjs"
}
},
paths: {
utils: "../js/utils",
widgets: "../js/widgets",
activity: "../js",
easel: "../lib/easeljs",
twewn: "../lib/tweenjs",
prefixfree: "../bower_components/prefixfree/prefixfree.min",
samples: "../sounds/samples",
planet: "../js/planet",
tonejsMidi: "../node_modules/@tonejs/midi/dist/Midi",
i18next: [
"../lib/i18next.min",
"https://cdn.jsdelivr.net/npm/i18next@23.11.5/dist/umd/i18next.min"
],
i18nextHttpBackend: [
"../lib/i18nextHttpBackend.min",
"https://cdn.jsdelivr.net/npm/i18next-http-backend@2.5.1/i18nextHttpBackend.min"
]
},
packages: []
});
requirejs(["i18next", "i18nextHttpBackend"], function (i18next, i18nextHttpBackend) {
function updateContent() {
const elements = document.querySelectorAll("[data-i18n]");
elements.forEach(element => {
const key = element.getAttribute("data-i18n");
element.textContent = i18next.t(key);
});
}
function initializeI18next() {
return new Promise(resolve => {
i18next.use(i18nextHttpBackend).init(
{
lng: "en",
fallbackLng: "en",
keySeparator: false,
nsSeparator: false,
interpolation: {
escapeValue: false
},
backend: {
loadPath: "locales/{{lng}}.json?v=" + Date.now()
}
},
function (err) {
if (err) {
console.error("i18next init failed:", err);
}
window.i18next = i18next;
resolve(i18next);
}
);
});
}
async function main() {
await initializeI18next();
const lang = "en";
i18next.changeLanguage(lang, function (err) {
if (err) {
console.error("Error changing language:", err);
return;
}
updateContent();
});
if (document.readyState === "loading") {
document.addEventListener("DOMContentLoaded", updateContent);
} else {
updateContent();
}
i18next.on("languageChanged", updateContent);
// Load app only after i18n is ready
requirejs(["utils/utils", "activity/activity"]);
}
main();
});