2021-08-04 09:26:49 +02:00
|
|
|
import { createI18n, LocaleMessages, VueMessageType } from 'vue-i18n'
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Load locale messages
|
|
|
|
*
|
|
|
|
* The loaded `JSON` locale messages is pre-compiled by `@intlify/vue-i18n-loader`, which is integrated into `vue-cli-plugin-i18n`.
|
|
|
|
* See: https://github.com/intlify/vue-i18n-loader#rocket-i18n-resource-pre-compilation
|
|
|
|
*/
|
2022-11-01 17:16:45 +01:00
|
|
|
|
2022-09-16 10:00:53 +02:00
|
|
|
function loadLocaleMessages(): Record<string, LocaleMessages<VueMessageType>> {
|
2021-08-04 09:53:17 +02:00
|
|
|
const locales = require.context('./locales', true, /[A-Za-z0-9-_,\s]+\.ts$/i)
|
2022-09-16 10:00:53 +02:00
|
|
|
const messages: Record<string, LocaleMessages<VueMessageType>> = {}
|
2021-08-04 09:26:49 +02:00
|
|
|
locales.keys().forEach((key) => {
|
|
|
|
const matched = key.match(/([A-Za-z0-9-_]+)\./i)
|
2023-06-24 19:14:02 +02:00
|
|
|
if (matched && matched.length > 1) {
|
2021-08-04 09:26:49 +02:00
|
|
|
const locale = matched[1]
|
2021-08-04 09:53:17 +02:00
|
|
|
messages[locale] = locales(key).default
|
2021-08-04 09:26:49 +02:00
|
|
|
}
|
|
|
|
})
|
|
|
|
return messages
|
|
|
|
}
|
|
|
|
|
|
|
|
export default createI18n({
|
|
|
|
legacy: false,
|
2021-08-04 13:59:51 +02:00
|
|
|
locale: 'en',
|
|
|
|
fallbackLocale: 'en',
|
|
|
|
globalInjection: true,
|
2021-08-04 09:26:49 +02:00
|
|
|
messages: loadLocaleMessages(),
|
|
|
|
})
|