mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core&ui: trigger i18n update event
This commit is contained in:
3 files changed
+9
-2
No files matched your search
@@ -313,7 +313,7 @@ function executeMiddlewareStack(context: any, middlewares: { name: string, func:
|
|||||||
return dispatch(0);
|
return dispatch(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
interface WebServiceConfig {
|
export interface WebServiceConfig {
|
||||||
keys: string[];
|
keys: string[];
|
||||||
proxy: boolean;
|
proxy: boolean;
|
||||||
cors?: string;
|
cors?: string;
|
||||||
@@ -697,7 +697,7 @@ declare module 'cordis' {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function apply(ctx: Context, config) {
|
export async function apply(ctx: Context, config: WebServiceConfig) {
|
||||||
ctx.provide('server', undefined, true);
|
ctx.provide('server', undefined, true);
|
||||||
ctx.server = new WebService(ctx, config);
|
ctx.server = new WebService(ctx, config);
|
||||||
}
|
}
|
||||||
@@ -7,6 +7,11 @@ declare module '../context' {
|
|||||||
i18n: I18nService;
|
i18n: I18nService;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
declare module '../service/bus' {
|
||||||
|
interface EventMap {
|
||||||
|
'app/i18n/update': (lang: string) => void;
|
||||||
|
}
|
||||||
|
}
|
||||||
declare global {
|
declare global {
|
||||||
interface String {
|
interface String {
|
||||||
translate: (...languages: string[]) => string;
|
translate: (...languages: string[]) => string;
|
||||||
@@ -22,6 +27,7 @@ class I18nService extends Service {
|
|||||||
this.ctx.effect(() => {
|
this.ctx.effect(() => {
|
||||||
translations[lang] ||= [];
|
translations[lang] ||= [];
|
||||||
translations[lang].unshift(content);
|
translations[lang].unshift(content);
|
||||||
|
this.ctx.emit('app/i18n/update', lang);
|
||||||
return () => {
|
return () => {
|
||||||
translations[lang] = translations[lang].filter((i) => i !== content);
|
translations[lang] = translations[lang].filter((i) => i !== content);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -145,5 +145,6 @@ export async function apply(ctx: Context) {
|
|||||||
ctx.on('system/setting', () => triggerHotUpdate());
|
ctx.on('system/setting', () => triggerHotUpdate());
|
||||||
ctx.on('app/watch/change', triggerHotUpdate);
|
ctx.on('app/watch/change', triggerHotUpdate);
|
||||||
ctx.on('app/watch/unlink', triggerHotUpdate);
|
ctx.on('app/watch/unlink', triggerHotUpdate);
|
||||||
|
ctx.on('app/i18n/update', debouncedBuildUI);
|
||||||
debouncedBuildUI();
|
debouncedBuildUI();
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user