v4.0.0: 덱 UX·i18n·썸네일 저장 개선 및 413 수정
즐겨찾기·홀드 미리보기·페이지 도움말·3개국어 번역을 추가하고, 덱 저장 시 썸네일을 1200px로 통일하며 Nginx/API 업로드 제한을 상향했다. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
72
script/page-i18n.js
Normal file
72
script/page-i18n.js
Normal file
@@ -0,0 +1,72 @@
|
||||
/**
|
||||
* data-i18n 속성 기반 페이지 번역
|
||||
*/
|
||||
(function initPageI18n() {
|
||||
/**
|
||||
* @returns {Promise<string>}
|
||||
*/
|
||||
function getLang() {
|
||||
const fromQuery = new URLSearchParams(window.location.search).get('lang');
|
||||
if (fromQuery) return fromQuery;
|
||||
return localStorage.getItem('lang') || 'ko';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} lang
|
||||
* @returns {Promise<object>}
|
||||
*/
|
||||
async function loadTranslations(lang) {
|
||||
try {
|
||||
const res = await fetch(`/i18n/translations.${lang}.json`);
|
||||
if (!res.ok) return {};
|
||||
return await res.json();
|
||||
} catch {
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
let cachedTranslations = {};
|
||||
|
||||
/**
|
||||
* @param {string} key
|
||||
* @param {string} [fallback]
|
||||
* @returns {string}
|
||||
*/
|
||||
function t(key, fallback = '') {
|
||||
return cachedTranslations[key] || fallback;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {object} translations
|
||||
*/
|
||||
function applyTranslations(translations) {
|
||||
document.querySelectorAll('[data-i18n]').forEach((el) => {
|
||||
const key = el.dataset.i18n;
|
||||
if (translations[key]) el.textContent = translations[key];
|
||||
});
|
||||
document.querySelectorAll('[data-i18n-html]').forEach((el) => {
|
||||
const key = el.dataset.i18nHtml;
|
||||
if (translations[key]) el.innerHTML = translations[key];
|
||||
});
|
||||
document.querySelectorAll('[data-i18n-placeholder]').forEach((el) => {
|
||||
const key = el.dataset.i18nPlaceholder;
|
||||
if (translations[key]) el.placeholder = translations[key];
|
||||
});
|
||||
if (window.UaPageHelp?.bindPageHelp) {
|
||||
window.UaPageHelp.bindPageHelp(translations);
|
||||
}
|
||||
}
|
||||
|
||||
async function applyPageI18n() {
|
||||
const lang = await getLang();
|
||||
cachedTranslations = await loadTranslations(lang);
|
||||
applyTranslations(cachedTranslations);
|
||||
return cachedTranslations;
|
||||
}
|
||||
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
applyPageI18n();
|
||||
});
|
||||
|
||||
window.UaPageI18n = { applyPageI18n, getLang, loadTranslations, t };
|
||||
})();
|
||||
Reference in New Issue
Block a user