Skip to content

Commit 1f60e0f

Browse files
fix language switch issue on login + added missing translations
1 parent 7a75488 commit 1f60e0f

File tree

8 files changed

+93
-25
lines changed

8 files changed

+93
-25
lines changed

client/packages/lowcoder/src/app.tsx

+3
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,9 @@ const AppIndexWithProps = connect(mapStateToProps, mapDispatchToProps)(AppIndex)
215215
export function bootstrap() {
216216
initApp();
217217
loadComps();
218+
219+
const uiLanguage = localStorage.getItem('lowcoder_uiLanguage');
220+
218221
const container = document.getElementById("root");
219222
const root = createRoot(container!);
220223
root.render(

client/packages/lowcoder/src/i18n/LanguageProvider.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ import React, { ReactNode } from 'react';
33
// Define the props expected by the LanguageProvider component
44
export interface LanguageProviderProps {
55
children: ReactNode;
6-
}
6+
}

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

+23-7
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,35 @@ 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 { ReactNode } from "react";
56

6-
const uiLanguage = localStorage.getItem('lowcoder_uiLanguage');
7+
type transType = (key: any, variables?: any) => string;
8+
type transToNodeType = (key: any, variables?: any) => ReactNode;
79

8-
export const { trans, transToNode, language } = new Translator<typeof localeData.en>(
9-
localeData,
10-
REACT_APP_LANGUAGES,
11-
[uiLanguage || 'en']
12-
);
10+
let trans: transType;
11+
let transToNode: transToNodeType;
12+
let language = 'en';
13+
14+
export const initTranslator = (lang?: string) => {
15+
const translator = new Translator<typeof localeData.en>(
16+
localeData,
17+
REACT_APP_LANGUAGES,
18+
[lang || 'en']
19+
);
20+
21+
language = translator.language;
22+
transToNode = translator.transToNode;
23+
trans = translator.trans;
24+
}
1325

1426
export const i18nObjs = getI18nObjects<I18nObjects>(localeData, REACT_APP_LANGUAGES);
1527

1628
export const languageList = Object.keys(languagesMetadata).map(code => ({
1729
languageCode: code,
1830
languageName: languagesMetadata[code].languageName,
1931
flag: languagesMetadata[code].flag
20-
}));
32+
}));
33+
34+
initTranslator();
35+
36+
export { language, trans, transToNode };

client/packages/lowcoder/src/i18n/locales/de.ts

+13-1
Original file line numberDiff line numberDiff line change
@@ -2249,7 +2249,19 @@ export const de: typeof en = {
22492249
"alreadySetPassword": "Passwort setzen",
22502250
"setPassPlaceholder": "Du kannst dich mit Passwort anmelden",
22512251
"setPassAfterBind": "Du kannst das Passwort nach der Kontobindung festlegen",
2252-
"socialConnections": "Soziale Bindungen"
2252+
"socialConnections": "Soziale Bindungen",
2253+
"changeAvatar": "Avatar ändern",
2254+
"about": "Um",
2255+
"userId": "Benutzer-ID",
2256+
"createdAt": "Hergestellt in",
2257+
"currentOrg": "aktuelle Organisation",
2258+
"settings": "Einstellungen",
2259+
"uiLanguage": "UI-Sprache",
2260+
"info": "Die Info",
2261+
"createdApps": "Erstellte Apps",
2262+
"createdModules": "Erstellte Module",
2263+
"onMarketplace": "Auf dem Marktplatz",
2264+
"howToPublish": "So veröffentlichen Sie auf dem Marktplatz"
22532265
},
22542266
"shortcut": {
22552267
...en.shortcut,

client/packages/lowcoder/src/i18n/locales/en.ts

+13-1
Original file line numberDiff line numberDiff line change
@@ -2302,7 +2302,19 @@ export const en = {
23022302
"alreadySetPassword": "Password Set",
23032303
"setPassPlaceholder": "You Can Login with Password",
23042304
"setPassAfterBind": "You Can Set Password After Account Bind",
2305-
"socialConnections": "Social Connections"
2305+
"socialConnections": "Social Connections",
2306+
"changeAvatar": "Change Avatar",
2307+
"about": "About",
2308+
"userId": "User ID",
2309+
"createdAt": "Created At",
2310+
"currentOrg": "Current Organization",
2311+
"settings": "Settings",
2312+
"uiLanguage": "UI Language",
2313+
"info": "Info",
2314+
"createdApps": "Created Apps",
2315+
"createdModules": "Created Modules",
2316+
"onMarketplace": "On Marketplace",
2317+
"howToPublish": "How to publish on Marketplace"
23062318
},
23072319
"shortcut": {
23082320
"shortcutList": "Keyboard Shortcuts",

client/packages/lowcoder/src/i18n/locales/zh.ts

+13
Original file line numberDiff line numberDiff line change
@@ -2136,6 +2136,18 @@ profile: {
21362136
setPassPlaceholder: "您可以使用密码登录",
21372137
setPassAfterBind: "账号绑定后,您可以设置密码",
21382138
socialConnections: "社交连接",
2139+
changeAvatar: "更改头像",
2140+
about: "关于",
2141+
userId: "用户身份",
2142+
createdAt: "创建于",
2143+
currentOrg: "当前组织",
2144+
settings: "设置",
2145+
uiLanguage: "用户界面语言",
2146+
info: "信息",
2147+
createdApps: "创建的应用程序",
2148+
createdModules: "创建的模块",
2149+
onMarketplace: "在市场上",
2150+
howToPublish: "如何在 Marketplace 上发布",
21392151
},
21402152
shortcut: {
21412153
shortcutList: "键盘快捷键",
@@ -2287,6 +2299,7 @@ history: {
22872299
history: "历史记录",
22882300
},
22892301
home: {
2302+
profile: "你的个人资料",
22902303
allApplications: "所有应用",
22912304
allModules: "所有模块",
22922305
allFolders: "所有文件夹",

client/packages/lowcoder/src/pages/ApplicationV2/UserProfileLayout.tsx

+24-15
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ export function UserProfileLayout(props: UserProfileLayoutProps) {
239239
<StyleProfileContent>
240240
<Row gutter={[24, 24]} style={{ display: 'flex', alignItems: 'end' }}>
241241
<Col lg={4}>
242-
<StyleAvatar src={<img src={user.avatarUrl} alt="avatar" />} shape="square" size={120} />
242+
<StyleAvatar src={<img src={user.avatarUrl ?? `https://eu.ui-avatars.com/api/?name=${user.username}&size=250`} alt="avatar" />} shape="square" size={120} />
243243
</Col>
244244
<Col lg={20}>
245245
<Space style={{paddingLeft : "80px"}}>
@@ -265,11 +265,12 @@ export function UserProfileLayout(props: UserProfileLayoutProps) {
265265
beforeUpload={beforeImgUpload}
266266
withCredentials
267267
>
268-
<Button style={{marginTop: "8px"}}>Change Avatar</Button>
268+
<Button style={{marginTop: "8px"}}>
269+
{trans("profile.changeAvatar")}
270+
</Button>
269271
</Upload>
270272

271273
<BlurFinishInput
272-
273274
valueCheck={{
274275
rule: (val) => val.trim() !== "",
275276
message: trans("profile.nameCheck"),
@@ -285,20 +286,20 @@ export function UserProfileLayout(props: UserProfileLayoutProps) {
285286
</Card>
286287

287288
<Card style={{ marginBottom: "20px" }}>
288-
<Title level={4}>About</Title>
289+
<Title level={4}>{trans("profile.about")}</Title>
289290
<Space direction="horizontal" size={10} wrap={true}>
290-
<Text>User-ID: {user.id}</Text> |
291-
<Text>Created At: {dayjs(user.createdTimeMs).format("YYYY-MM-DD HH:mm:ss")}</Text> |
292-
<Text>Current Organization: {currentOrg?.name}</Text>
291+
<Text>{trans("profile.userId")}: {user.id}</Text> |
292+
<Text>{trans("profile.createdAt")}: {dayjs(user.createdTimeMs).format("YYYY-MM-DD HH:mm:ss")}</Text> |
293+
<Text>{trans("profile.currentOrg")}: {currentOrg?.name}</Text>
293294
</Space>
294295
</Card>
295296

296297
<Card style={{ marginBottom: "20px" }}>
297-
<Title level={4}>Settings</Title>
298+
<Title level={4}>{trans("profile.settings")}</Title>
298299
<Space direction="vertical" size={10}>
299-
<Text>UI Language:</Text>
300+
<Text>{trans("profile.uiLanguage")}:</Text>
300301
<Select
301-
defaultValue={currentUser.uiLanguage}
302+
defaultValue={currentUser.uiLanguage ?? 'en'}
302303
style={{ width: 200 }}
303304
onChange={handleLanguageChange}
304305
showSearch
@@ -316,14 +317,16 @@ export function UserProfileLayout(props: UserProfileLayoutProps) {
316317
</Card>
317318

318319
<Card style={{ marginBottom: "20px" }}>
319-
<Title level={4}>Info</Title>
320+
<Title level={4}>{trans("profile.info")}</Title>
320321
<Space direction="horizontal" size={10}>
321322
<Row gutter={[24,24]}>
322323
<Col xs={24} sm={12} xl={6} style={{marginBottom: "20px", minWidth: "300px"}} span={8}>
323324
<Card hoverable>
324325
<div style={{ display: "flex", justifyContent: "space-between" }}>
325326
<div>
326-
<p style={{ textTransform: "uppercase", fontSize: "13px" }}>Created Apps</p>
327+
<p style={{ textTransform: "uppercase", fontSize: "13px" }}>
328+
{trans("profile.createdApps")}
329+
</p>
327330
<h4 style={{ fontSize: "22px" }}>
328331
<span data-target={apps.filter(app => app.createBy === user.username && app.applicationType == 1).length}>
329332
<CountUp start={0} end={apps.filter(app => app.createBy === user.username && app.applicationType == 1).length} duration={2} />
@@ -343,7 +346,9 @@ export function UserProfileLayout(props: UserProfileLayoutProps) {
343346
<Card hoverable>
344347
<div style={{ display: "flex", justifyContent: "space-between" }}>
345348
<div>
346-
<p style={{ textTransform: "uppercase", fontSize: "13px" }}>Created Modules</p>
349+
<p style={{ textTransform: "uppercase", fontSize: "13px" }}>
350+
{trans("profile.createdModules")}
351+
</p>
347352
<h4 style={{ fontSize: "22px" }}>
348353
<span data-target={apps.filter(app => app.createBy === user.username && app.applicationType == 2).length}>
349354
<CountUp start={0} end={apps.filter(app => app.createBy === user.username && app.applicationType == 2).length} duration={2} />
@@ -363,14 +368,18 @@ export function UserProfileLayout(props: UserProfileLayoutProps) {
363368
<Card hoverable>
364369
<div style={{ display: "flex", justifyContent: "space-between" }}>
365370
<div>
366-
<p style={{ textTransform: "uppercase", fontSize: "13px" }}>on Marketplace</p>
371+
<p style={{ textTransform: "uppercase", fontSize: "13px" }}>
372+
{trans("profile.onMarketplace")}
373+
</p>
367374
<h4 style={{ fontSize: "22px" }}>
368375
<span data-target={8}>
369376
<CountUp start={0} end={8} duration={2} />
370377
</span>
371378
</h4>
372379
<div style={{ display: "flex", alignItems: "center" }}>
373-
<h5 style={{ color: "#55c27f", marginRight: "10px" }}>How to publish on Marketplce</h5>
380+
<h5 style={{ color: "#55c27f", marginRight: "10px" }}>
381+
{trans("profile.howToPublish")}
382+
</h5>
374383
</div>
375384
</div>
376385
<BgSuccess style={{ padding: '6px', width: '48px', height: '48px', borderRadius: '4px', display: 'flex', alignItems: 'center', justifyContent: 'center' }}>

client/packages/lowcoder/src/redux/sagas/userSagas.ts

+3
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import { messageInstance } from "lowcoder-design/src/components/GlobalInstances"
2424

2525
import { AuthSearchParams } from "constants/authConstants";
2626
import { saveAuthSearchParams } from "pages/userAuth/authUtils";
27+
import { initTranslator } from "i18n";
2728

2829
function validResponseData(response: AxiosResponse<ApiResponse>) {
2930
return response && response.data && response.data.data;
@@ -90,6 +91,8 @@ export function* getCurrentUserSaga() {
9091
type: ReduxActionTypes.FETCH_CURRENT_USER_SUCCESS,
9192
payload: response.data.data,
9293
});
94+
const { uiLanguage } = response.data.data;
95+
initTranslator(uiLanguage);
9396
}
9497
} catch (error: any) {
9598
yield put({

0 commit comments

Comments
 (0)