mirror of
https://github.com/sotam0316/drawNET_test.git
synced 2026-04-25 03:58:38 +09:00
폴더 및 하위 파일 업로드
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
import { state } from './state.js';
|
||||
import { logger } from './utils/logger.js';
|
||||
|
||||
export async function initI18n() {
|
||||
const lang = state.language;
|
||||
|
||||
try {
|
||||
const response = await fetch(`/static/locales/${lang}.json`);
|
||||
const translations = await response.json();
|
||||
const enResponse = await fetch('/static/locales/en.json');
|
||||
const enTranslations = await enResponse.json();
|
||||
|
||||
state.i18n = { ...enTranslations, ...translations };
|
||||
applyTranslations();
|
||||
logger.high(`i18n initialized for [${lang}]`);
|
||||
} catch (err) {
|
||||
logger.critical("Failed to load locales", err);
|
||||
}
|
||||
}
|
||||
|
||||
export function t(key) {
|
||||
return (state.i18n && state.i18n[key]) || key;
|
||||
}
|
||||
|
||||
export function applyTranslations() {
|
||||
const elements = document.querySelectorAll('[data-i18n]');
|
||||
elements.forEach(el => {
|
||||
const key = el.getAttribute('data-i18n');
|
||||
const translation = t(key);
|
||||
|
||||
if (el.tagName === 'INPUT' || el.tagName === 'TEXTAREA') {
|
||||
el.placeholder = translation;
|
||||
} else if (el.title) {
|
||||
el.title = translation;
|
||||
} else {
|
||||
el.innerText = translation;
|
||||
}
|
||||
});
|
||||
|
||||
// Handle Title specifically if needed
|
||||
const searchInput = document.getElementById('asset-search');
|
||||
if (searchInput) searchInput.placeholder = t('search_placeholder');
|
||||
}
|
||||
Reference in New Issue
Block a user