mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core&ui: i18n: fix serialize
This commit is contained in:
1 parent
e1228345b0
commit
4976f94ec0
3 files changed
+7
-4
No files matched your search
@@ -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 {
|
||||||
|
|||||||
@@ -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;
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -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';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user