35 lines
1.1 KiB
TypeScript
35 lines
1.1 KiB
TypeScript
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`
|
|
|
|
try {
|
|
const { data } = await useFetch(translationApi, {
|
|
method: 'GET',
|
|
headers: {
|
|
'Content-Type': 'application/json;charset=UTF-8'
|
|
}
|
|
})
|
|
|
|
|
|
if(locale === 'zh-cn') {
|
|
locale = 'zh-CN'
|
|
}
|
|
|
|
// 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] || {}
|
|
}
|
|
})
|