diff --git a/lib/i18n.ts b/lib/i18n.ts index bb3f5cf5..4328247c 100644 --- a/lib/i18n.ts +++ b/lib/i18n.ts @@ -1,16 +1,17 @@ -import { createI18n, I18n } from 'vue-i18n' +import { createI18n, I18n, I18nOptions } from 'vue-i18n' import fr from '@/locales/fr.json' import en from '@/locales/en.json' export const locale: string = 'en' export const fallbackLocale: string = 'en' -// https://vue-i18n.intlify.dev/guide/advanced/composition.html#implicit-with-injected-properties-and-functions -export const i18n: I18n = createI18n({ +export const options: I18nOptions = { warnHtmlMessage: false, + // https://vue-i18n.intlify.dev/guide/advanced/composition.html#implicit-with-injected-properties-and-functions globalInjection: true, legacy: false, locale, fallbackLocale, messages: { fr, en } -}) +} +export const i18n: I18n = createI18n(options) diff --git a/lib/main.ts b/lib/main.ts index c473e8df..beece9a9 100644 --- a/lib/main.ts +++ b/lib/main.ts @@ -4,7 +4,7 @@ import * as components from './components' import * as datavisualisations from './datavisualisations' import * as maps from './maps' import config from './config' -import { App,Component,DefineComponent } from 'vue' +import { App,Component, DefineComponent } from 'vue' export { default as AccordionWrapper } from './components/AccordionWrapper.vue' export { default as AccordionStep } from './components/AccordionStep.vue' @@ -48,6 +48,11 @@ export { default as SymbolMap } from './maps/SymbolMap.vue' type ComponentMap = {[name:string]:Component|DefineComponent} +type PluginOptions = { + useI18n?: boolean, + useBootstrap?: boolean, + useConfig?: boolean +} const Murmur = { get i18n() { @@ -79,18 +84,29 @@ const Murmur = { // @ts-expect-error not sure why typescript sees an error here return Murmur.i18n.global.locale.value }, - install(app: App) { - app.use(createBootstrap()) - app.use(i18n) + install(app: App, { useI18n = true, useBootstrap = true, useConfig = true }: PluginOptions = {}) { + + if (useBootstrap) { + app.use(createBootstrap()) + } - app.config.globalProperties.$config = Murmur.config + if (useI18n) { + app.use(Murmur.i18n) + } + + if (useConfig) { + app.config.globalProperties.$config = Murmur.config + } + Object.keys(this.components).forEach((key) => app.component(key, this.components[key]) ) Object.keys(this.datavisualisations).forEach((key) => app.component(key, this.datavisualisations[key]) ) - Object.keys(this.maps).forEach((key) => app.component(key, this.maps[key])) + Object.keys(this.maps).forEach((key) => + app.component(key, this.maps[key]) + ) } }