feat: localize interview questions (ko/en), send X-Lang header
This commit is contained in:
@@ -89,6 +89,7 @@ els.sessionForm.addEventListener("submit", async (event) => {
|
||||
.map((item) => item.trim())
|
||||
.filter(Boolean),
|
||||
interview_timeline: value("#timeline"),
|
||||
lang: localStorage.getItem("tutor_lang") || document.documentElement.lang || "ko",
|
||||
};
|
||||
|
||||
try {
|
||||
@@ -216,7 +217,7 @@ function renderSession() {
|
||||
"aria-pressed",
|
||||
String(state.selectedQuestion?.id === question.id)
|
||||
);
|
||||
button.innerHTML = `<span class="question-id">${escapeHTML(question.id)}</span>${escapeHTML(question.prompt)}`;
|
||||
button.innerHTML = `<span class="question-id">${escapeHTML(question.id)}</span>${escapeHTML(tq(question.id) || question.prompt)}`;
|
||||
button.addEventListener("click", () => {
|
||||
state.selectedQuestion = question;
|
||||
els.answerText.value = "";
|
||||
@@ -465,7 +466,8 @@ els.logoutButton.addEventListener("click", () => {
|
||||
|
||||
async function request(url, options = {}) {
|
||||
const token = localStorage.getItem("tutor_token");
|
||||
const headers = { "Content-Type": "application/json" };
|
||||
const lang = localStorage.getItem("tutor_lang") || document.documentElement.lang || "ko";
|
||||
const headers = { "Content-Type": "application/json", "X-Lang": lang };
|
||||
if (token) headers["Authorization"] = `Bearer ${token}`;
|
||||
const response = await fetch(url, { headers, ...options });
|
||||
const body = await response.json();
|
||||
|
||||
@@ -181,6 +181,33 @@ window.t = function (key, ...args) {
|
||||
return typeof text === "function" ? text(...args) : text;
|
||||
}
|
||||
|
||||
var questionTexts = {
|
||||
ko: {
|
||||
"backend-http-idempotency":
|
||||
"HTTP 메서드가 멱등성을 가지려면 어떤 조건이 필요하며, 재시도 시 왜 중요한가요?",
|
||||
"backend-db-index-tradeoff":
|
||||
"데이터베이스 인덱스를 추가하면 API가 어떻게 개선되며, 어떤 트레이드오프가 발생할 수 있나요?",
|
||||
"backend-cache-invalidation":
|
||||
"API 응답을 캐싱할지 어떻게 결정하며, 오래된 데이터는 어떻게 처리하나요?",
|
||||
},
|
||||
en: {
|
||||
"backend-http-idempotency":
|
||||
"What makes an HTTP method idempotent, and why does that matter for retries?",
|
||||
"backend-db-index-tradeoff":
|
||||
"When would adding a database index improve an API, and what tradeoffs can it introduce?",
|
||||
"backend-cache-invalidation":
|
||||
"How would you decide whether to cache an API response, and how would you handle stale data?",
|
||||
},
|
||||
};
|
||||
|
||||
window.tq = function (id) {
|
||||
const lang =
|
||||
localStorage.getItem("tutor_lang") ||
|
||||
document.documentElement.lang ||
|
||||
"ko";
|
||||
return questionTexts[lang]?.[id] ?? questionTexts["en"]?.[id] ?? "";
|
||||
};
|
||||
|
||||
window.updateStaticText = function () {
|
||||
const lang =
|
||||
localStorage.getItem("tutor_lang") ||
|
||||
|
||||
Reference in New Issue
Block a user