| 1 | import { z } from 'zod' |
| 2 | import { getLocale } from '../interceptors/request-context.interceptor' |
| 3 | |
| 4 | export const i18nObjectSchema = z.object({ |
| 5 | 'en-US': z.string(), |
| 6 | 'zh-CN': z.string(), |
| 7 | }) |
| 8 | |
| 9 | export type I18nObject = z.infer<typeof i18nObjectSchema> |
| 10 | |
| 11 | export function zodI18nString() { |
| 12 | return i18nObjectSchema.transform((obj) => { |
| 13 | const locale = getLocale() |
| 14 | return obj[locale] || obj['en-US'] |
| 15 | }) |
| 16 | } |
| 17 |