refactor: use lazy loading for localization files

This commit is contained in:
pa
2025-11-18 20:59:41 +09:00
committed by Natsumi
parent fdeb8fa38f
commit 0bc9980cae
19 changed files with 51 additions and 52 deletions

37
src/localization/index.js Normal file
View 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 };