Skip to content

Commit 6116f93

Browse files
committed
process downloading one language in lowcoder-design
1 parent 1c8ce4f commit 6116f93

File tree

3 files changed

+33
-7
lines changed

3 files changed

+33
-7
lines changed
Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,30 @@
1-
import { Translator } from "lowcoder-core";
1+
import { getI18nObjects, Translator } from "lowcoder-core";
22
import * as localeData from "./locales";
3+
import { ReactNode } from "react";
34

4-
export const { trans } = new Translator<typeof localeData.en>(localeData, REACT_APP_LANGUAGES);
5+
type transType = (key: any, variables?: any) => string;
6+
type transToNodeType = (key: any, variables?: any) => ReactNode;
7+
8+
let trans: transType;
9+
let transToNode: transToNodeType;
10+
let language = 'en';
11+
12+
export const initTranslator = async (lang?: string) => {
13+
let langJson = await (localeData as any)[lang || 'en']();
14+
langJson = {[lang || 'en']: langJson}
15+
const translator = new Translator<typeof langJson>(
16+
langJson,
17+
REACT_APP_LANGUAGES,
18+
[lang || 'en']
19+
);
20+
21+
language = translator.language;
22+
transToNode = (key: any, variables?: any) => translator.transToNode?.(key, variables);
23+
trans = (key: any, variables?: any) => translator.trans?.(key, variables);
24+
}
25+
26+
const langJson = await (localeData as any)[REACT_APP_LANGUAGES || 'en']();
27+
28+
await initTranslator();
29+
30+
export { language, trans, transToNode };
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// file examples: en, enGB, zh, zhHK
22
// fallback example: current locale is zh-HK, fallback order is zhHK => zh => en
3-
export * from "./en";
4-
export * from "./zh";
5-
export * from "./de";
6-
export * from "./pt"
3+
export const en = async () : Promise<Object> => await import("./en").then(module => module.en);
4+
export const zh = async () : Promise<Object> => await import("./zh").then(module => module.zh);
5+
export const de = async () : Promise<Object> => await import("./de").then(module => module.de);
6+
export const pt = async () : Promise<Object> => await import("./pt").then(module => module.pt);

client/packages/lowcoder-design/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"compilerOptions": {
3-
"target": "es5",
3+
"target": "es2017",
44
"experimentalDecorators": true,
55
"lib": ["dom", "dom.iterable", "esnext"],
66
"allowJs": true,

0 commit comments

Comments
 (0)