-
-
Notifications
You must be signed in to change notification settings - Fork 366
/
Copy pathi18n.config.ts
42 lines (40 loc) · 1.16 KB
/
i18n.config.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import MarkdownIt from 'markdown-it'
import commonData from '@/i18n/locales/all_lang.json'
const locales = import.meta.glob('./i18n/locales/*.json', { eager: true })
const md = MarkdownIt({
breaks: false,
})
function getMessages() {
const messages: { [x: string]: string } = {}
for (const [key, value] of Object.entries(locales)) {
const matched = key.match(/([A-Za-z0-9-_]+)\./i)
if (matched && matched.length > 1) {
const locale = matched[1]
if (locale === 'all_lang') {
continue
}
messages[locale] = value.default
}
}
return messages
}
export default defineI18nConfig(() => ({
skipSettingLocaleOnNavigate: true,
warnHtmlMessage: false,
defaultLocale: 'en',
detectBrowserLanguage: {
useCookie: true,
cookieKey: 'lang',
fallbackLocale: 'en',
alwaysRedirect: true,
},
strategy: 'no_prefix',
locale: process.env.VUE_APP_I18N_LOCALE || 'en',
fallbackLocale: process.env.VUE_APP_I18N_FALLBACK_LOCALE || 'en',
silentTranslationWarn: true,
modifiers: {
md: str => md.renderInline(str),
common: str => str.split('.').reduce((o, i) => o[i], commonData),
},
messages: getMessages(),
}))