core&ui: i18n: fix serialize

This commit is contained in:
undefined committed 2022-11-05 18:07:05 +08:00
1 parent e1228345b0
commit 4976f94ec0
3 files changed
+7 -4

No files matched your search

+1 -1
View File
@@ -736,7 +736,7 @@ export interface HydroGlobal {
error: typeof import('./error'); error: typeof import('./error');
Logger: typeof import('./logger').Logger; Logger: typeof import('./logger').Logger;
logger: typeof import('./logger').logger; logger: typeof import('./logger').logger;
locales: Record<string, Record<string, string>>; locales: Record<string, Record<string, string> | Record<symbol, Record<string, string>>>;
} }
declare global { declare global {
+5 -2
View File
@@ -62,8 +62,11 @@ global.Hydro.locales = new Proxy(translations, {
get(self, lang: string) { get(self, lang: string) {
if (!self[lang]) return {}; if (!self[lang]) return {};
return new Proxy(self[lang], { return new Proxy(self[lang], {
get(s, key: string) { get(s, key) {
return app.i18n.get(key, lang); if (typeof key === 'string') return app.i18n.get(key, lang);
const result = {};
for (let i = s.length - 1; i; i--) Object.assign(result, s[i]);
return result;
}, },
}); });
}, },
+1 -1
View File
@@ -152,7 +152,7 @@ class UiConstantsHandler extends ResourceHandler {
class LanguageHandler extends ResourceHandler { class LanguageHandler extends ResourceHandler {
async all({ lang }) { async all({ lang }) {
if (!global.Hydro.locales[lang]) lang = SystemModel.get('server.language'); if (!global.Hydro.locales[lang]) lang = SystemModel.get('server.language');
this.response.body = `window.LOCALES=${JSON.stringify(global.Hydro.locales[lang])};`; this.response.body = `window.LOCALES=${JSON.stringify(global.Hydro.locales[lang][Symbol.for('iterate')])};`;
this.response.type = 'application/javascript'; this.response.type = 'application/javascript';
} }
} }