|
1 | 1 | import type { FluentBundle, FluentResource, FluentVariable } from '@fluent/bundle' |
2 | 2 | import type { TranslationWithAttrs } from './TranslationContext' |
3 | 3 | import type { FluentVueOptions } from './types' |
4 | | -import type { InstallFunction, Vue2, Vue3, Vue3Component } from './types/typesCompat' |
5 | | -import { isVue3, shallowRef } from 'vue-demi' |
| 4 | +import type { InstallFunction, Vue2, Vue3 } from './types/typesCompat' |
| 5 | +import { getCurrentInstance, isVue3, shallowRef } from 'vue-demi' |
6 | 6 |
|
7 | 7 | import { registerFluentVueDevtools } from './devtools' |
8 | 8 |
|
@@ -83,13 +83,15 @@ export function createFluentVue(options: FluentVueOptions): FluentVue { |
83 | 83 | key: string, |
84 | 84 | value?: Record<string, FluentVariable>, |
85 | 85 | ) { |
86 | | - return getContext(rootContext, this as Vue3Component).format(key, value) |
| 86 | + const instance = getCurrentInstance() |
| 87 | + return getContext(rootContext, instance?.proxy).format(key, value) |
87 | 88 | } |
88 | 89 | vue3.config.globalProperties[resolvedOptions.globalFormatAttrsName] = function ( |
89 | 90 | key: string, |
90 | 91 | value?: Record<string, FluentVariable>, |
91 | 92 | ) { |
92 | | - return getContext(rootContext, this as Vue3Component).formatAttrs(key, value) |
| 93 | + const instance = getCurrentInstance() |
| 94 | + return getContext(rootContext, instance?.proxy).formatAttrs(key, value) |
93 | 95 | } |
94 | 96 |
|
95 | 97 | vue3.directive(resolvedOptions.directiveName, createVue3Directive(rootContext)) |
|
0 commit comments