提交正式官网
This commit is contained in:
@@ -0,0 +1,117 @@
|
||||
import {
|
||||
|
||||
doctors,
|
||||
|
||||
getHospitalById,
|
||||
|
||||
getDoctorsByHospitalId,
|
||||
|
||||
hospitals
|
||||
|
||||
} from '~/data/hospitals-content'
|
||||
|
||||
import { hospitalsPageContentBundle } from '~/data/hospitals-page-content'
|
||||
|
||||
import { doctorZh } from '~/data/locale/zh/doctors.zh'
|
||||
|
||||
import { hospitalIntroZh } from '~/data/locale/zh/hospitals-intros.zh'
|
||||
|
||||
import { hospitalNameZh } from '~/data/locale/zh/hospitals-names.zh'
|
||||
|
||||
import type { DoctorRecord, HospitalRecord } from '~/data/hospitals-content'
|
||||
|
||||
|
||||
|
||||
function localizeHospital(h: HospitalRecord, locale: 'en' | 'zh'): HospitalRecord {
|
||||
|
||||
if (locale !== 'zh') return h
|
||||
|
||||
const intro = hospitalIntroZh[h.id]
|
||||
|
||||
const name = hospitalNameZh[h.id]
|
||||
|
||||
return {
|
||||
|
||||
...h,
|
||||
|
||||
...(name ? { name } : {}),
|
||||
|
||||
...(intro ? { intro } : {})
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
function localizeDoctor(d: DoctorRecord, locale: 'en' | 'zh'): DoctorRecord {
|
||||
|
||||
if (locale !== 'zh') return d
|
||||
|
||||
const zh = doctorZh[d.id]
|
||||
|
||||
return zh ? { ...d, ...zh } : d
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
export function useLocalizedHospitals() {
|
||||
|
||||
const { locale } = useSiteLocale()
|
||||
|
||||
const page = useLocalized(hospitalsPageContentBundle)
|
||||
|
||||
|
||||
|
||||
const localizedHospitals = computed(() =>
|
||||
|
||||
hospitals.map((h) => localizeHospital(h, locale.value))
|
||||
|
||||
)
|
||||
|
||||
|
||||
|
||||
const localizedDoctors = computed(() =>
|
||||
|
||||
doctors.map((d) => localizeDoctor(d, locale.value))
|
||||
|
||||
)
|
||||
|
||||
|
||||
|
||||
function getLocalizedHospitalById(id: string) {
|
||||
|
||||
const h = getHospitalById(id)
|
||||
|
||||
return h ? localizeHospital(h, locale.value) : undefined
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
function getLocalizedDoctorsByHospitalId(hospitalId: string) {
|
||||
|
||||
return getDoctorsByHospitalId(hospitalId).map((d) => localizeDoctor(d, locale.value))
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
return {
|
||||
|
||||
page,
|
||||
|
||||
hospitals: localizedHospitals,
|
||||
|
||||
doctors: localizedDoctors,
|
||||
|
||||
getHospitalById: getLocalizedHospitalById,
|
||||
|
||||
getDoctorsByHospitalId: getLocalizedDoctorsByHospitalId
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user