refactor: i18n 수정

This commit is contained in:
“hyeonggkim”
2025-11-04 19:19:58 +09:00
parent ed15adc850
commit 7130313bfc
11 changed files with 263 additions and 308 deletions

View File

@@ -1,29 +1,27 @@
import fallback from './fallback/pt'
export default defineI18nLocale(async (locale: string) => {
//https://static-pubcomm.gate8.com/dev/test/multilingual/test_common_template.json?20251021185116
const config = useRuntimeConfig()
const rootPath = config.public.staticUrl
const runType = config.public.runType
const translationApi = `${rootPath}/${runType}/test/multilingual/test_common_template.json`
const runtimeConfig = useRuntimeConfig()
const dataResourcesUrl = runtimeConfig.public.dataResourcesUrl as string
const multilingualFileName = 'test_common_template.json'
try {
const { data } = await useFetch(translationApi, {
method: 'GET',
headers: {
'Content-Type': 'application/json;charset=UTF-8'
}
const resultGetMultilingual = await useGetMultilingual({
baseApiUrl: dataResourcesUrl,
fileName: multilingualFileName,
})
// API 데이터에서 locale에 는 데이터 추출
const apiData = data.value?.[locale] || {} // locale에 맞는 데이터가 없으면 빈 객체 반환
// API 데이터와 common.json 데이터를 병합 (common.json이 우선순위)
const finalResult = { ...apiData }
return finalResult
} catch (error) {
console.error('Error fetching translation data:', error)
// 에러 발생 시 common.json 데이터라도 반환
return commonData[locale] || {}
// multilingual 객체에서 현재 locale에 해당하는 데이터 추출
const multilingualData = resultGetMultilingual?.value?.multilingual
if (multilingualData && typeof multilingualData === 'object') {
// locale이 'ko'이므로 'ko' 키의 데이터를 반환
const localeData = multilingualData[locale] || multilingualData['pt'] || {}
return localeData
}
return {}
} catch (e) {
console.error('[Exception] ko.defineI18nLocale: ', e)
return fallback
}
})