11<script setup lang="ts">
2- import { ref , type Ref } from ' vue'
2+ import { ref , watch } from ' vue'
33import { useI18n } from ' vue-i18n'
4- import { API } from ' ./net' ;
5- import { Cache } from ' ./cache' ;
4+ import { API } from ' ./net'
65
76interface Props {
87 name: string
98}
109const props = defineProps <Props >()
11- const { t, locale } = useI18n ()
10+ const { locale } = useI18n ()
1211
13- interface PluginAppContext {
14- i18n: {
15- t: (key : string ) => string
16- locale: Ref <string >
17- }
18- API: typeof API
19- Cache: typeof Cache
20- }
21-
22- const pluginContext: PluginAppContext = {
23- i18n: { t , locale },
24- API ,
25- Cache
26- }
12+ let pluginInstance: { setLocale? : (value : string ) => void } | undefined
2713
2814const loading = ref (true )
2915const loadPlugin = async (): Promise <void > => {
@@ -44,14 +30,16 @@ const loadPlugin = async (): Promise<void> => {
4430
4531 // Implement retry mechanism with exponential backoff
4632 const checkPluginLoad = (retries = 0 , maxRetries = 10 ) => {
47- const globalScope = globalThis as { ATestPlugin? : { mount? : (el : Element , context : PluginAppContext ) => void } };
33+ const globalScope = globalThis as { ATestPlugin? : { mount? : (el : Element ) => void , setLocale ? : ( value : string ) => void } };
4834 const plugin = globalScope .ATestPlugin ;
4935
5036 if (plugin && plugin .mount ) {
5137 const container = document .getElementById (" plugin-container" );
5238 if (container ) {
5339 container .innerHTML = ' ' ; // Clear previous content
54- plugin .mount (container , pluginContext );
40+ plugin .mount (container );
41+ plugin .setLocale ?.(locale .value );
42+ pluginInstance = plugin ;
5543 loading .value = false ;
5644 } else {
5745 loading .value = false ;
@@ -78,6 +66,11 @@ loadPlugin().catch((error) => {
7866 loading .value = false ;
7967 console .error (' Failed to initialize extension plugin' , error );
8068});
69+
70+ watch (locale , (value ) => {
71+ const normalized = value ?? ' en' ;
72+ pluginInstance ?.setLocale ?.(normalized );
73+ });
8174 </script >
8275
8376<template >
0 commit comments