Skip to content

Commit

Permalink
feat(i18n): load messages with import.meta.glob
Browse files Browse the repository at this point in the history
  • Loading branch information
mnenie committed Jan 22, 2025
1 parent 528a0c0 commit aaaca90
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions apps/client/src/shared/libs/i18n/index.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,41 @@
import { createI18n, type I18n } from 'vue-i18n'
import { enZod, ruZod, zhZod } from '../vee-validate/rules'
import { enLocale, ruLocale, zhLocale } from './locales'
import { customPluralRule } from './plurals'
import useDayJsLocalize from './dayjs'
import { getCurrentLocale } from './utils/getLocale'

export type MessageSchema = typeof enLocale
const ru_ru = import.meta.glob('./locales/**/ru-RU.ts', { eager: true })
const en_us = import.meta.glob('./locales/**/en-US.ts', { eager: true })
const zh_cn = import.meta.glob('./locales/**/zh-CN.ts', { eager: true })

function loadLang(modules: Record<string, any>) {
const messages: { [key: string]: string } = {}

Object.keys(modules).forEach((module) => {
Object.assign(messages, { ...modules[module].default })
})
return messages
}

export interface MessageSchema {
[key: string]: any
}

const messages = {
'en-US': {
...enLocale,
...loadLang(en_us),
errors: {
...enZod,
},
},
'ru-RU': {
...ruLocale,
...loadLang(ru_ru),
errors: {
...ruZod,
},
},
'zh-CN': {
...zhLocale,
...loadLang(zh_cn),
errors: {
...zhZod,
},
Expand Down

0 comments on commit aaaca90

Please sign in to comment.