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
124 lines (113 loc) · 3.73 KB
/
loader.js
File metadata and controls
124 lines (113 loc) · 3.73 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
// 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"
},
"p5.min": {
exports: "p5"
},
"p5-adapter": {
deps: ["p5.min"]
},
"p5.sound.min": {
deps: ["p5-adapter"]
},
"p5.dom.min": {
deps: ["p5.min"]
},
"p5-sound-adapter": {
deps: ["p5.sound.min"]
}
},
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",
"p5.min": "../lib/p5.min",
"p5.sound.min": "../lib/p5.sound.min",
"p5.dom.min": "../lib/p5.dom.min",
"p5-adapter": "../js/p5-adapter",
"p5-sound-adapter": "../js/p5-sound-adapter",
"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();
});