Skip to content

Commit 3483de7

Browse files
author
FalkWolsky
committed
User Profile, Countries, Language Switch
1 parent a7ae487 commit 3483de7

File tree

17 files changed

+255
-101
lines changed

17 files changed

+255
-101
lines changed

client/packages/lowcoder-core/lib/index.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,9 @@ declare const i18n: {
648648
region?: string | undefined;
649649
locales: string[];
650650
};
651+
651652
declare function getValueByLocale<T>(defaultValue: T, func: (info: LocaleInfo) => T | undefined): T;
653+
652654
type AddDot<T extends string> = T extends "" ? "" : `.${T}`;
653655
type ValidKey<T> = Exclude<keyof T, symbol>;
654656
type NestedKey<T> = (T extends object ? {
@@ -658,6 +660,7 @@ type AddPrefix<T, P extends string> = {
658660
[K in keyof T as K extends string ? `${P}${K}` : never]: T[K];
659661
};
660662
declare const globalMessages: AddPrefix<{}, "@">;
663+
661664
type GlobalMessageKey = NestedKey<typeof globalMessages>;
662665
type VariableValue = string | number | boolean | Date | React.ReactNode;
663666

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import IntlMessageFormat from "intl-messageformat";
33
import log from "loglevel";
44
import { Fragment } from "react";
55

6-
const defaultLocale = "en";
6+
const defaultLocale = "de";
77

88
let locales = [defaultLocale];
99

client/packages/lowcoder/src/app.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,11 @@ import { loadComps } from "comps";
4444
import { initApp } from "util/commonUtils";
4545
import { favicon } from "assets/images";
4646
import { hasQueryParam } from "util/urlUtils";
47-
import { isFetchUserFinished } from "redux/selectors/usersSelectors";
47+
import { getCurrentUser, isFetchUserFinished } from "redux/selectors/usersSelectors";
4848
import { SystemWarning } from "./components/SystemWarning";
4949
import { getBrandingConfig } from "./redux/selectors/configSelectors";
5050
import { buildMaterialPreviewURL } from "./util/materialUtils";
5151
import GlobalInstances from 'components/GlobalInstances';
52-
// import { LanguageProvider } from './i18n/LanguageContext';
5352

5453
const LazyUserAuthComp = React.lazy(() => import("pages/userAuth"));
5554
const LazyInviteLanding = React.lazy(() => import("pages/common/inviteLanding"));
@@ -61,10 +60,10 @@ const LazyApplicationHome = React.lazy(() => import("pages/ApplicationV2"));
6160
const LazyDebugComp = React.lazy(() => import("./debug"));
6261
const LazyDebugNewComp = React.lazy(() => import("./debugNew"));
6362

64-
const Wrapper = (props: { children: React.ReactNode }) => (
63+
const Wrapper = (props: { children: React.ReactNode, language: string }) => (
6564
<ConfigProvider
6665
theme={{ hashed: false }}
67-
locale={getAntdLocale(language)}
66+
locale={getAntdLocale(props.language)}
6867
>
6968
<App>
7069
<GlobalInstances />
@@ -82,6 +81,7 @@ type AppIndexProps = {
8281
getCurrentUser: () => void;
8382
favicon: string;
8483
brandName: string;
84+
uiLanguage: string;
8585
};
8686

8787
class AppIndex extends React.Component<AppIndexProps, any> {
@@ -107,8 +107,9 @@ class AppIndex extends React.Component<AppIndexProps, any> {
107107
const hideLoadingHeader = isTemplate || isAuthUnRequired(pathname);
108108
return <ProductLoading hideHeader={hideLoadingHeader} />;
109109
}
110+
110111
return (
111-
<Wrapper>
112+
<Wrapper language={this.props.uiLanguage}>
112113
<Helmet>
113114
{<title>{this.props.brandName}</title>}
114115
{<link rel="icon" href={this.props.favicon} />}
@@ -196,6 +197,7 @@ const mapStateToProps = (state: AppState) => ({
196197
? buildMaterialPreviewURL(getBrandingConfig(state)?.favicon!)
197198
: favicon,
198199
brandName: getBrandingConfig(state)?.brandName ?? trans("productName"),
200+
uiLanguage: state.ui.users.user.uiLanguage,
199201
});
200202

201203
const mapDispatchToProps = (dispatch: any) => ({
@@ -214,7 +216,7 @@ export function bootstrap() {
214216
const root = createRoot(container!);
215217
root.render(
216218
<Provider store={reduxStore}>
217-
<AppIndexWithProps />
219+
<AppIndexWithProps />
218220
</Provider>
219221
);
220222
}
Lines changed: 19 additions & 0 deletions
Loading

client/packages/lowcoder/src/comps/comps/tourComp/tourTooltips.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { trans } from "@lowcoder-ee/i18n";
1+
import { trans } from "i18n";
22

33
const indicatorsRenderExample = `(current, total) => (
44
<span>

client/packages/lowcoder/src/constants/userConstants.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ export const defaultUser: User = {
6161
export type CurrentUser = {
6262
id: string;
6363
name: string;
64+
uiLanguage: string;
6465
avatarUrl: string;
6566
email: string;
6667
ip: string;
@@ -74,6 +75,7 @@ export type CurrentUser = {
7475
export const defaultCurrentUser: CurrentUser = {
7576
id: "",
7677
name: ANONYMOUS_USERNAME,
78+
uiLanguage: "en",
7779
avatarUrl: "",
7880
email: "",
7981
ip: "",
Lines changed: 104 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,128 @@
1-
import en_GB from "antd/es/locale/en_GB";
21
import en_US from "antd/es/locale/en_US";
32
import zh_CN from "antd/es/locale/zh_CN";
43
import zh_HK from "antd/es/locale/zh_HK";
54
import zh_TW from "antd/es/locale/zh_TW";
5+
import es_ES from "antd/es/locale/es_ES";
6+
import fr_CA from "antd/es/locale/fr_CA";
7+
import fr_FR from "antd/es/locale/fr_FR";
8+
import de_DE from "antd/es/locale/de_DE";
9+
import it_IT from "antd/es/locale/it_IT";
10+
import ar_EG from "antd/es/locale/ar_EG";
11+
import th_TH from "antd/es/locale/th_TH";
12+
import vi_VN from "antd/es/locale/vi_VN";
13+
import ms_MY from "antd/es/locale/ms_MY";
14+
import id_ID from "antd/es/locale/id_ID";
15+
import hi_IN from "antd/es/locale/hi_IN";
16+
import ta_IN from "antd/es/locale/ta_IN";
17+
import kn_IN from "antd/es/locale/kn_IN";
18+
import ml_IN from "antd/es/locale/ml_IN";
19+
import ru_RU from "antd/es/locale/ru_RU";
20+
import pl_PL from "antd/es/locale/pl_PL";
21+
import cs_CZ from "antd/es/locale/cs_CZ";
22+
import uk_UA from "antd/es/locale/uk_UA";
23+
import bg_BG from "antd/es/locale/bg_BG";
24+
import sr_RS from "antd/es/locale/sr_RS";
25+
import hr_HR from "antd/es/locale/hr_HR";
26+
import sk_SK from "antd/es/locale/sk_SK";
27+
import sl_SI from "antd/es/locale/sl_SI";
28+
import mk_MK from "antd/es/locale/mk_MK";
29+
30+
631
import { getValueByLocale } from "lowcoder-core";
732

833
export function getAntdLocale(language?: string) {
34+
935
if (language) {
1036
return selectAntdLocale(language, "");
1137
}
1238
return getValueByLocale(en_US, (locale) => selectAntdLocale(locale.language, locale.region));
1339
}
1440

1541
function selectAntdLocale(language: string, region?: string) {
42+
1643
switch (language) {
17-
case "en":
18-
switch (region) {
19-
case "GB":
20-
return en_GB;
21-
}
22-
return en_US;
2344
case "zh":
2445
switch (region) {
2546
case "HK":
2647
return zh_HK;
2748
case "TW":
2849
return zh_TW;
50+
default:
51+
return zh_CN;
52+
}
53+
case "es":
54+
switch (region) {
55+
case "ES":
56+
return es_ES;
57+
default:
58+
return es_ES;
2959
}
30-
return zh_CN;
60+
case "fr":
61+
switch (region) {
62+
case "CA":
63+
return fr_CA;
64+
case "FR":
65+
return fr_FR;
66+
default:
67+
return fr_FR;
68+
}
69+
case "it":
70+
return it_IT;
71+
case "de":
72+
switch (region) {
73+
case "DE":
74+
return de_DE;
75+
default:
76+
return de_DE;
77+
}
78+
case "ru": // Russian
79+
return ru_RU;
80+
case "pl": // Polish
81+
return pl_PL;
82+
case "cs": // Czech
83+
return cs_CZ;
84+
case "uk": // Ukrainian
85+
return uk_UA;
86+
case "bg": // Bulgarian
87+
return bg_BG;
88+
case "sr": // Serbian
89+
return sr_RS;
90+
case "hr": // Croatian
91+
return hr_HR;
92+
case "sk": // Slovak
93+
return sk_SK;
94+
case "sl": // Slovenian
95+
return sl_SI;
96+
case "mk": // Macedonian
97+
return mk_MK;
98+
case "ar":
99+
switch (region) {
100+
case "SA":
101+
return ar_EG;
102+
case "EG":
103+
return ar_EG;
104+
default:
105+
return ar_EG;
106+
}
107+
case "th": // Thai
108+
return th_TH;
109+
case "vi":
110+
return vi_VN; // Vietnamese (Vietnam)
111+
case "ms":
112+
return ms_MY; // Malay (Malaysia)
113+
case "id":
114+
return id_ID; // Indonesian (Indonesia)
115+
case "hi": // Hindi
116+
return hi_IN; // Hindi (India)
117+
case "ta": // Tamil
118+
return ta_IN; // Tamil (India)
119+
case "kn": // Kannada
120+
return kn_IN; // Kannada (India)
121+
case "ml": // Malayalam
122+
return ml_IN; // Malayalam (India)
123+
124+
// Additional languages would follow this pattern
125+
default:
126+
return en_US; // Fallback to English (US) if language is not recognized
31127
}
32128
}

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,12 @@ import { getI18nObjects, Translator } from "lowcoder-core";
22
import * as localeData from "./locales";
33
import { I18nObjects } from "./locales/types";
44
import { languagesMetadata } from "./languagesMeta";
5-
import { useSelector } from "react-redux";
6-
75

86
export const { trans, transToNode, language } = new Translator<typeof localeData.en>(
97
localeData,
108
REACT_APP_LANGUAGES,
11-
["de"]
129
);
10+
1311
export const i18nObjs = getI18nObjects<I18nObjects>(localeData, REACT_APP_LANGUAGES);
1412

1513
export const languageList = Object.keys(languagesMetadata).map(code => ({

0 commit comments

Comments
 (0)