feat. i18n 설정

This commit is contained in:
김채린
2025-09-09 04:09:54 +00:00
parent 9581e5d356
commit a3dee13089
45 changed files with 2929 additions and 2374 deletions

View File

@@ -0,0 +1,35 @@
import { useGameDataStore } from "#layers/stores/useGameDataStore";
export default defineNuxtRouteMiddleware(async (to, from) => {
// 서버 사이드에서는 스킵
if (import.meta.server) {
return;
}
const gameDataStore = useGameDataStore();
// gameData가 로드되지 않았으면 스킵 (다른 미들웨어에서 로드됨)
if (!gameDataStore.gameData) {
return;
}
// 현재 경로에서 언어 코드 추출
// 예: /ko/about/story -> ko
// 예: /en/test/page -> en
const languagePattern = /^\/([a-z]{2})(?:\/|$)/;
const match = to.path.match(languagePattern);
const currentLangCode = match ? match[1] : null;
console.log("🚀 3333~ currentLangCode:", currentLangCode)
// 허용된 언어 코드 목록
const allowedLangCodes = gameDataStore.gameData.lang_codes || [];
console.log("🚀 ~ allowedLangCodes:", allowedLangCodes)
// 현재 언어가 허용된 언어 목록에 없으면 404로 리다이렉트
if (currentLangCode && !allowedLangCodes.includes(currentLangCode)) {
throw createError({
statusCode: 404,
statusMessage: "Language not supported"
});
}
});