Skip to content

Only one language download, revert lowcoder-design element back to origin. #1227

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
process downloading one language
  • Loading branch information
Imiss-U1025 committed Oct 4, 2024
commit 1c8ce4fe15201c703cacdc47c5c38a056b2a98d8
17 changes: 10 additions & 7 deletions client/packages/lowcoder/src/i18n/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,29 @@ let trans: transType;
let transToNode: transToNodeType;
let language = 'en';

export const initTranslator = (lang?: string) => {
const translator = new Translator<typeof localeData.en>(
localeData,
export const initTranslator = async (lang?: string) => {
let langJson = await (localeData as any)[lang || 'en']();
langJson = {[lang || 'en']: langJson}
const translator = new Translator<typeof langJson>(
langJson,
REACT_APP_LANGUAGES,
[lang || 'en']
);

language = translator.language;
transToNode = translator.transToNode;
trans = translator.trans;
transToNode = (key: any, variables?: any) => translator.transToNode?.(key, variables);
trans = (key: any, variables?: any) => translator.trans?.(key, variables);
}

export const i18nObjs = getI18nObjects<I18nObjects>(localeData, REACT_APP_LANGUAGES);
const langJson = await (localeData as any)[REACT_APP_LANGUAGES || 'en']();
export const i18nObjs = getI18nObjects<I18nObjects>(langJson, REACT_APP_LANGUAGES || 'en');

export const languageList = Object.keys(languagesMetadata).map(code => ({
languageCode: code,
languageName: languagesMetadata[code].languageName,
flag: languagesMetadata[code].flag
}));

initTranslator();
await initTranslator();

export { language, trans, transToNode };
22 changes: 11 additions & 11 deletions client/packages/lowcoder/src/i18n/locales/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// file examples: en, enGB, zh, zhHK
// fallback example: current locale is zh-HK, fallback order is zhHK => zh => en
export * from "./de";
export * from "./en";
export * from "./it";
export * from "./pt";
export * from "./es";
export * from "./zh";
export * from "./ru";
export const de = async ():Promise<object> => await import("./de").then(module => (module.de));
export const en = async ():Promise<object> => await import("./en").then(module => (module.en));
export const it = async ():Promise<object> => await import("./it").then(module => (module.it));
export const pt = async ():Promise<object> => await import("./pt").then(module => (module.pt));
export const es = async ():Promise<object> => await import("./es").then(module => (module.es));
export const zh = async ():Promise<object> => await import("./zh").then(module => (module.zh));
export const ru = async ():Promise<object> => await import("./ru").then(module => (module.ru));

export * from "./enObj";
export * from "./deObj";
export * from "./itObj";
export * from "./zhObj";
export const enObj = async ():Promise<object> => await import("./enObj").then(module => (module.enObj));
export const deObj = async ():Promise<object | undefined> => await import("./deObj").then(module => (module.deObj));
export const itObj = async ():Promise<object> => await import("./itObj").then(module => (module.itObj));
export const zhObj = async ():Promise<object | undefined> => await import("./zhObj").then(module => (module.zhObj));
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ function addQuery(editorState: EditorState, datasourceInfos: DatasourceInfo[]) {
name: queryName,
compType: "restApi",
comp: {
path: i18nObjs.editorTutorials.mockDataUrl || enObj.editorTutorials.mockDataUrl,
path: i18nObjs.editorTutorials.mockDataUrl,
bodyType: "application/json",
},
datasourceId: QUICK_REST_API_ID,
Expand Down