mirror of
https://github.com/MrUnknownDE/VRCX.git
synced 2026-04-26 18:23:47 +02:00
refactor: use lazy loading for localization files
This commit is contained in:
37
src/localization/index.js
Normal file
37
src/localization/index.js
Normal file
@@ -0,0 +1,37 @@
|
||||
const langCodes = [
|
||||
'cs',
|
||||
'en',
|
||||
'es',
|
||||
'fr',
|
||||
'hu',
|
||||
'ja',
|
||||
'ko',
|
||||
'pl',
|
||||
'pt',
|
||||
'ru',
|
||||
'th',
|
||||
'vi',
|
||||
'zh-CN',
|
||||
'zh-TW'
|
||||
];
|
||||
|
||||
async function getLocalizationStrings() {
|
||||
const urlPromises = Promise.all(
|
||||
langCodes.map((code) =>
|
||||
import(`./${code}.json?url`).then((m) => m.default)
|
||||
)
|
||||
);
|
||||
|
||||
const urls = await urlPromises;
|
||||
const fetchPromises = Promise.all(
|
||||
urls.map((url) => fetch(url).then((res) => res.json()))
|
||||
);
|
||||
const results = await fetchPromises;
|
||||
const entries = langCodes.map((code, index) => {
|
||||
return [code, results[index]];
|
||||
});
|
||||
|
||||
return Object.fromEntries(entries);
|
||||
}
|
||||
|
||||
export { getLocalizationStrings };
|
||||
Reference in New Issue
Block a user