Skip to content

Commit 43e6934

Browse files
committed
Remove need to inject root context into the component
1 parent 1ce011f commit 43e6934

File tree

2 files changed

+4
-7
lines changed

2 files changed

+4
-7
lines changed

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ export function createFluentVue(options: FluentVueOptions): FluentVue {
9292
vue2.directive(resolvedOptions.directiveName, createVue2Directive(rootContext))
9393
}
9494

95-
(vue as Vue).component(resolvedOptions.componentName, createComponent(resolvedOptions))
95+
(vue as Vue).component(resolvedOptions.componentName, createComponent(resolvedOptions, rootContext))
9696
},
9797
}
9898
}

src/vue/component.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,15 @@ import {
44
defineComponent,
55
getCurrentInstance,
66
h,
7-
inject,
87
isVue2,
98
} from 'vue-demi'
109
import type { ResolvedOptions, SimpleNode } from 'src/types'
1110
import type { VueComponent } from 'src/types/typesCompat'
1211

1312
import { camelize } from '../util/camelize'
1413
import { getContext } from '../getContext'
15-
import { RootContextSymbol } from '../symbols'
16-
import { assert, warn } from '../util/warn'
14+
import { warn } from '../util/warn'
15+
import type { TranslationContext } from '../TranslationContext'
1716

1817
function getParentWithFluent(
1918
instance: VueComponent | null | undefined,
@@ -31,7 +30,7 @@ function getParentWithFluent(
3130
// &, &, &.
3231
const reMarkup = /<|&#?\w+;/
3332

34-
export function createComponent(options: ResolvedOptions) {
33+
export function createComponent(options: ResolvedOptions, rootContext: TranslationContext) {
3534
return defineComponent({
3635
name: options.componentName,
3736
props: {
@@ -42,8 +41,6 @@ export function createComponent(options: ResolvedOptions) {
4241
noTag: { type: Boolean, default: false },
4342
},
4443
setup(props, { slots, attrs }) {
45-
const rootContext = inject(RootContextSymbol)
46-
assert(rootContext != null, 'i18n component used without installing plugin')
4744
const instance = getCurrentInstance()
4845
const parent = getParentWithFluent(instance?.proxy)
4946
const fluent = getContext(rootContext, parent)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy