56 lines
1.7 KiB
TypeScript
56 lines
1.7 KiB
TypeScript
/**
|
|
* i18n 다국어 로더 플러그인
|
|
* S3에서 공통 다국어 파일을 로드하여 i18n 메시지에 주입합니다.
|
|
*/
|
|
export default defineNuxtPlugin(async nuxtApp => {
|
|
const $i18n = nuxtApp.$i18n as any
|
|
|
|
const runtimeConfig = useRuntimeConfig()
|
|
const dataResourcesUrl = runtimeConfig.public.dataResourcesUrl as string
|
|
const commonTranslations = 'STOVE_PUBTEMPLATE_common_translations.json'
|
|
|
|
const gameDataStore = useGameDataStore()
|
|
const { gameData } = storeToRefs(gameDataStore)
|
|
const langCodes = gameData.value?.lang_codes
|
|
|
|
if (!langCodes || langCodes.length === 0) {
|
|
return
|
|
}
|
|
|
|
try {
|
|
const url = `${dataResourcesUrl}/multilingual/${commonTranslations}`
|
|
const translations = await commonFetch('GET', url)
|
|
|
|
if (!translations || typeof translations !== 'object') {
|
|
return
|
|
}
|
|
|
|
// 로케일 코드 변환 맵 (소문자 하이픈 -> 대문자 하이픈)
|
|
const localeMap: Record<string, string> = {
|
|
'zh-tw': 'zh-TW',
|
|
'zh-cn': 'zh-CN',
|
|
}
|
|
|
|
langCodes.forEach(langCode => {
|
|
// 로케일 코드 변환 (필요한 경우)
|
|
const normalizedLangCode = localeMap[langCode] || langCode
|
|
|
|
// 대소문자 구분 없이 로케일 데이터 찾기
|
|
const localeData =
|
|
translations[normalizedLangCode] ||
|
|
translations[normalizedLangCode.toLowerCase()] ||
|
|
translations[langCode] ||
|
|
translations[langCode.toLowerCase()]
|
|
|
|
if (localeData && typeof localeData === 'object') {
|
|
$i18n.setLocaleMessage(langCode, localeData)
|
|
}
|
|
})
|
|
} catch (error) {
|
|
console.error(
|
|
'[Exception] i18n-loader: Failed to load translations:',
|
|
error
|
|
)
|
|
}
|
|
})
|