FitTrackee/fittrackee_client/src/i18n.ts

35 lines
1.1 KiB
TypeScript
Raw Normal View History

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
*/
const disabledLanguages = ['nb', 'nl'] // to remove after norwegian translations release
2022-11-01 17:16:45 +01:00
2022-09-16 10:00:53 +02:00
function loadLocaleMessages(): Record<string, LocaleMessages<VueMessageType>> {
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)
2022-11-01 17:16:45 +01:00
if (
matched &&
matched.length > 1 &&
!disabledLanguages.includes(matched[1])
) {
2021-08-04 09:26:49 +02:00
const locale = matched[1]
messages[locale] = locales(key).default
2021-08-04 09:26:49 +02:00
}
})
return messages
}
export default createI18n({
legacy: false,
locale: 'en',
fallbackLocale: 'en',
globalInjection: true,
2021-08-04 09:26:49 +02:00
messages: loadLocaleMessages(),
})