Skip to content

Commit

Permalink
build: add options to use i18n and bootstrap vue
Browse files Browse the repository at this point in the history
  • Loading branch information
pirhoo committed May 31, 2024
1 parent d0c6149 commit 6a73ff5
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
9 changes: 5 additions & 4 deletions lib/i18n.ts
Original file line number Diff line number Diff line change
@@ -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)
28 changes: 22 additions & 6 deletions lib/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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<Element>) {
app.use(createBootstrap())
app.use(i18n)
install(app: App<Element>, { 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])
)
}
}

Expand Down

0 comments on commit 6a73ff5

Please sign in to comment.