import type { LocaleObject, NuxtI18nOptions } from '@nuxtjs/i18n' // const LANG_DIR: string = './i18n/locales' const DEFAULT_COVERAGES: string[] = [ 'en', 'ja', 'ko', 'zh-tw', 'fr', 'de', 'es', 'pt', 'th', 'zh-cn', ] const DEFAULT_LOCALES: Record = { en: { code: 'en', name: 'English', iso: 'en', dir: 'ltr' }, 'zh-tw': { code: 'zh-tw', name: '繁體中文', iso: 'zh-tw', dir: 'ltr' }, ja: { code: 'ja', name: '日本語', iso: 'ja', dir: 'ltr' }, ko: { code: 'ko', name: '한국어', iso: 'ko-KR', dir: 'ltr' }, fr: { code: 'fr', name: 'Français', iso: 'fr', dir: 'ltr' }, de: { code: 'de', name: 'Deutsch', iso: 'de', dir: 'ltr' }, es: { code: 'es', name: 'Español', iso: 'es', dir: 'ltr' }, pt: { code: 'pt', name: 'Português', iso: 'pt', dir: 'ltr' }, th: { code: 'th', name: 'ภาษาไทย', iso: 'th', dir: 'ltr' }, 'zh-cn': { code: 'zh-cn', name: '简体中文', iso: 'zh-cn', dir: 'ltr' }, } const DEFAULT_LOCALE_CODE = 'ko' // getI18n 함수가 NuxtI18nOptions 타입의 값을 반환하도록 명시적으로 타입을 지정합니다. const getI18n = (allowedLangCodes?: string[]): NuxtI18nOptions => { // allowedLangCodes가 제공되면 해당 언어들만 사용, 그렇지 않으면 모든 기본 언어 사용 const targetCoverages = allowedLangCodes && allowedLangCodes.length > 0 ? DEFAULT_COVERAGES.filter(code => allowedLangCodes.includes(code)) : DEFAULT_COVERAGES const DEFAULT_LOCALE_COVERAGES_SET: LocaleObject[] = targetCoverages.map( code => ({ code: code as LocaleObject['code'], file: `${code}.ts`, // 아래의 옵셔널 체이닝(?.)은 해당 코드가 undefined일 경우를 안전하게 처리합니다. name: DEFAULT_LOCALES[code]?.name ?? code, iso: DEFAULT_LOCALES[code]?.iso ?? code, // dir 속성은 모든 로케일 객체에 공통적으로 존재하므로, 여기서 추가할 수도 있습니다. dir: DEFAULT_LOCALES[code]?.dir ?? 'ltr', }) ) return { baseUrl: process.env.BASE_URL, strategy: 'prefix', vueI18n: 'custom', locales: DEFAULT_LOCALE_COVERAGES_SET, defaultLocale: DEFAULT_LOCALE_CODE, detectBrowserLanguage: { fallbackLocale: DEFAULT_LOCALE_CODE, useCookie: true, cookieKey: 'LOCALE', cookieDomain: process.env.BASE_DOMAIN, redirectOn: 'root', }, langDir: '../i18n/locales', compilation: { strictMessage: false, escapeHtml: false, }, debug: false, // 동적으로 언어 제외 설정을 위한 pages 설정 // customRoutes: 'config', // pages: // allowedLangCodes && allowedLangCodes.length > 0 // ? generatePageExclusions(allowedLangCodes) // : {}, // 추가적인 설정이 필요하다면 여기에 포함시킬 수 있습니다. } } // gameData.lang_codes를 기반으로 언어 제외 설정을 생성하는 함수 // const generatePageExclusions = ( // allowedLangCodes: string[] // ): Record => { // const exclusions: Record = {} // // 모든 기본 언어에 대해 제외 설정 생성 // DEFAULT_COVERAGES.forEach(langCode => { // if (!allowedLangCodes.includes(langCode)) { // // 해당 언어가 허용되지 않으면 모든 페이지에서 제외 // exclusions[langCode] = false // } // }) // return exclusions // } export { DEFAULT_LOCALE_CODE, DEFAULT_COVERAGES, getI18n }