Files
web-temp/layers/composables/useDynamicI18nRoutes.ts
2025-09-09 04:09:54 +00:00

70 lines
2.1 KiB
TypeScript

import type { GameDataValue } from '#layers/types/api/gameData'
import { DEFAULT_COVERAGES } from '@/i18n.config'
/**
* gameData.lang_codes를 기반으로 동적으로 언어 제외 설정을 생성하는 컴포저블
*/
export const useDynamicI18nRoutes = () => {
const gameDataStore = useGameDataStore()
/**
* 현재 gameData의 lang_codes를 기반으로 허용된 언어 목록을 반환
*/
const getAllowedLangCodes = (): string[] => {
const gameData = gameDataStore.gameData
return gameData?.lang_codes || []
}
/**
* 특정 언어가 허용되는지 확인
*/
const isLangAllowed = (langCode: string): boolean => {
const allowedLangCodes = getAllowedLangCodes()
return allowedLangCodes.length === 0 || allowedLangCodes.includes(langCode)
}
/**
* defineI18nRoute에서 사용할 수 있는 언어 제외 설정을 생성
* @param pagePath - 페이지 경로 (선택사항)
* @returns 언어 제외 설정 객체
*/
const getI18nRouteConfig = (pagePath?: string) => {
const allowedLangCodes = getAllowedLangCodes()
// 허용된 언어가 없으면 모든 언어 허용
if (allowedLangCodes.length === 0) {
return undefined
}
// 허용된 언어만 포함하는 설정 반환
return {
locales: allowedLangCodes
}
}
/**
* 특정 언어를 제외하는 설정을 생성
* @param excludedLangCodes - 제외할 언어 코드 배열
* @returns 언어 제외 설정 객체
*/
const getExcludedLangConfig = (excludedLangCodes: string[]) => {
const allowedLangCodes = getAllowedLangCodes()
// 허용된 언어에서 제외할 언어를 제거
const finalAllowedCodes = allowedLangCodes.length > 0
? allowedLangCodes.filter(code => !excludedLangCodes.includes(code))
: ['en', 'ja', 'ko', 'zh-tw', 'fr', 'de', 'es', 'pt', 'th', 'zh-cn'].filter(code => !excludedLangCodes.includes(code))
return {
locales: finalAllowedCodes
}
}
return {
getAllowedLangCodes,
isLangAllowed,
getI18nRouteConfig,
getExcludedLangConfig
}
}