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
133 lines (114 loc) · 4.05 KB
/
Copy pathloader.js
File metadata and controls
133 lines (114 loc) · 4.05 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
125
126
127
128
129
130
131
132
133
// 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() {
console.log("asdasdasd");
console.log("updateContent() called"); // Debugging line
const elements = document.querySelectorAll("[data-i18n]");
elements.forEach((element) => {
const key = element.getAttribute("data-i18n");
const translation = i18next.t(key);
element.textContent = translation;
});
}
async function initializeI18next() {
return new Promise((resolve, reject) => {
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, t) {
if (err) {
console.error("i18next init failed:", err);
reject(err);
} else {
console.log("i18next initialized");
window.i18next = i18next;
console.log("i18next Store:", i18next.store.data);
resolve(i18next);
}
});
i18next.on("initialized", function() {
console.log("i18next initialized");
});
i18next.on("loaded", function(loaded) {
console.log("i18next loaded:", loaded);
});
});
}
async function main() {
try {
await initializeI18next();
if (document.readyState === "loading") {
document.addEventListener("DOMContentLoaded", function() {
updateContent();
});
} else {
console.log("DOM already loaded, updating content immediately");
updateContent();
}
} catch (error) {
console.error("Error initializing i18next:", error);
}
}
main().then(() => {
requirejs(["utils/utils", "activity/activity"]);
});
i18next.changeLanguage(lang, (err, t) => {
if (err) {
console.error("Error changing language:", err);
return;
}
updateContent();
});
i18next.on("languageChanged", function() {
updateContent();
});
});
// requirejs(["utils/utils", "activity/activity"]);