国际化系统

This commit is contained in:
YHH
2025-10-14 23:56:54 +08:00
parent 3a5e73266e
commit 3224bb9696
8 changed files with 340 additions and 23 deletions

View File

@@ -0,0 +1,30 @@
import { useState, useEffect } from 'react';
import { Core } from '@esengine/ecs-framework';
import { LocaleService, type Locale } from '@esengine/editor-core';
export function useLocale() {
const localeService = Core.services.resolve(LocaleService);
const [locale, setLocale] = useState<Locale>(localeService.getCurrentLocale());
useEffect(() => {
const unsubscribe = localeService.onChange((newLocale) => {
setLocale(newLocale);
});
return unsubscribe;
}, [localeService]);
const t = (key: string, fallback?: string) => {
return localeService.t(key, fallback);
};
const changeLocale = (newLocale: Locale) => {
localeService.setLocale(newLocale);
};
return {
locale,
t,
changeLocale
};
}