Skip to content

Commit 1c8ce4f

Browse files
committed
process downloading one language
1 parent 43bf2fe commit 1c8ce4f

File tree

3 files changed

+22
-19
lines changed

3 files changed

+22
-19
lines changed

client/packages/lowcoder/src/i18n/index.tsx

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,29 @@ let trans: transType;
1111
let transToNode: transToNodeType;
1212
let language = 'en';
1313

14-
export const initTranslator = (lang?: string) => {
15-
const translator = new Translator<typeof localeData.en>(
16-
localeData,
14+
export const initTranslator = async (lang?: string) => {
15+
let langJson = await (localeData as any)[lang || 'en']();
16+
langJson = {[lang || 'en']: langJson}
17+
const translator = new Translator<typeof langJson>(
18+
langJson,
1719
REACT_APP_LANGUAGES,
1820
[lang || 'en']
1921
);
2022

2123
language = translator.language;
22-
transToNode = translator.transToNode;
23-
trans = translator.trans;
24+
transToNode = (key: any, variables?: any) => translator.transToNode?.(key, variables);
25+
trans = (key: any, variables?: any) => translator.trans?.(key, variables);
2426
}
2527

26-
export const i18nObjs = getI18nObjects<I18nObjects>(localeData, REACT_APP_LANGUAGES);
28+
const langJson = await (localeData as any)[REACT_APP_LANGUAGES || 'en']();
29+
export const i18nObjs = getI18nObjects<I18nObjects>(langJson, REACT_APP_LANGUAGES || 'en');
2730

2831
export const languageList = Object.keys(languagesMetadata).map(code => ({
2932
languageCode: code,
3033
languageName: languagesMetadata[code].languageName,
3134
flag: languagesMetadata[code].flag
3235
}));
3336

34-
initTranslator();
37+
await initTranslator();
3538

3639
export { language, trans, transToNode };
Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
// file examples: en, enGB, zh, zhHK
22
// fallback example: current locale is zh-HK, fallback order is zhHK => zh => en
3-
export * from "./de";
4-
export * from "./en";
5-
export * from "./it";
6-
export * from "./pt";
7-
export * from "./es";
8-
export * from "./zh";
9-
export * from "./ru";
3+
export const de = async ():Promise<object> => await import("./de").then(module => (module.de));
4+
export const en = async ():Promise<object> => await import("./en").then(module => (module.en));
5+
export const it = async ():Promise<object> => await import("./it").then(module => (module.it));
6+
export const pt = async ():Promise<object> => await import("./pt").then(module => (module.pt));
7+
export const es = async ():Promise<object> => await import("./es").then(module => (module.es));
8+
export const zh = async ():Promise<object> => await import("./zh").then(module => (module.zh));
9+
export const ru = async ():Promise<object> => await import("./ru").then(module => (module.ru));
1010

11-
export * from "./enObj";
12-
export * from "./deObj";
13-
export * from "./itObj";
14-
export * from "./zhObj";
11+
export const enObj = async ():Promise<object> => await import("./enObj").then(module => (module.enObj));
12+
export const deObj = async ():Promise<object | undefined> => await import("./deObj").then(module => (module.deObj));
13+
export const itObj = async ():Promise<object> => await import("./itObj").then(module => (module.itObj));
14+
export const zhObj = async ():Promise<object | undefined> => await import("./zhObj").then(module => (module.zhObj));

client/packages/lowcoder/src/pages/tutorials/editorTutorials.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ function addQuery(editorState: EditorState, datasourceInfos: DatasourceInfo[]) {
193193
name: queryName,
194194
compType: "restApi",
195195
comp: {
196-
path: i18nObjs.editorTutorials.mockDataUrl || enObj.editorTutorials.mockDataUrl,
196+
path: i18nObjs.editorTutorials.mockDataUrl,
197197
bodyType: "application/json",
198198
},
199199
datasourceId: QUICK_REST_API_ID,

0 commit comments

Comments
 (0)