Skip to content

Commit 97f7f6f

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

File tree

15 files changed

+120
-70
lines changed

15 files changed

+120
-70
lines changed

client/packages/lowcoder-core/lib/index.cjs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11513,6 +11513,7 @@ var IntlMessageFormat = IntlMessageFormat$1;
1151311513

1151411514
var defaultLocale = "en";
1151511515
var locales = [defaultLocale];
11516+
1151611517
if (globalThis.navigator) {
1151711518
if (navigator.languages && navigator.languages.length > 0) {
1151811519
locales = __spreadArray([], navigator.languages, true);
@@ -11521,6 +11522,7 @@ if (globalThis.navigator) {
1152111522
locales = [navigator.language || navigator.userLanguage || defaultLocale];
1152211523
}
1152311524
}
11525+
1152411526
function parseLocale(s) {
1152511527
var locale = s.trim();
1152611528
if (!locale) {

client/packages/lowcoder-core/lib/index.js

Lines changed: 64 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7581,15 +7581,62 @@ function requireReactJsxRuntime_development () {
75817581
} (jsxRuntime));
75827582

75837583
var en = {};
7584-
75857584
var zh = {};
7585+
var de = {};
7586+
var fr = {};
7587+
var es = {};
7588+
var it = {};
7589+
var ar = {};
7590+
var th = {};
7591+
var vi = {};
7592+
var ms = {};
7593+
var id = {};
7594+
var hi = {};
7595+
var ta = {};
7596+
var kn = {};
7597+
var ml = {};
7598+
var ru = {};
7599+
var pl = {};
7600+
var cs = {};
7601+
var uk = {};
7602+
var bg = {};
7603+
var sr = {};
7604+
var hr = {};
7605+
var sk = {};
7606+
var sl = {};
7607+
var mk = {};
7608+
var pt = {};
75867609

75877610
// file examples: en, enGB, zh, zhHK
75887611

75897612
var localeData = /*#__PURE__*/Object.freeze({
75907613
__proto__: null,
75917614
en: en,
7592-
zh: zh
7615+
zh: zh,
7616+
de: de,
7617+
fr: fr,
7618+
es: es,
7619+
it: it,
7620+
ar: ar,
7621+
th: th,
7622+
vi: vi,
7623+
ms: ms,
7624+
id: id,
7625+
hi: hi,
7626+
ta: ta,
7627+
kn: kn,
7628+
ml: ml,
7629+
ru: ru,
7630+
pl: pl,
7631+
cs: cs,
7632+
uk: uk,
7633+
bg: bg,
7634+
sr: sr,
7635+
hr: hr,
7636+
sk: sk,
7637+
sl: sl,
7638+
mk: mk,
7639+
pt: pt
75937640
});
75947641

75957642
var ErrorKind;
@@ -11505,14 +11552,22 @@ var IntlMessageFormat = IntlMessageFormat$1;
1150511552

1150611553
var defaultLocale = "en";
1150711554
var locales = [defaultLocale];
11555+
11556+
// Falk - Adapted the central translator to check if a localStorage key is existing.
11557+
11558+
const uiLanguage = localStorage.getItem('lowcoder_uiLanguage');
1150811559
if (globalThis.navigator) {
11509-
if (navigator.languages && navigator.languages.length > 0) {
11560+
if (uiLanguage) {
11561+
locales = [uiLanguage];
11562+
}
11563+
else if (navigator.languages && navigator.languages.length > 0) {
1151011564
locales = __spreadArray([], navigator.languages, true);
1151111565
}
1151211566
else {
1151311567
locales = [navigator.language || navigator.userLanguage || defaultLocale];
1151411568
}
1151511569
}
11570+
1151611571
function parseLocale(s) {
1151711572
var locale = s.trim();
1151811573
if (!locale) {
@@ -11572,9 +11627,13 @@ function getDataByLocale(fileData, suffix, filterLocales, targetLocales) {
1157211627
return { data: data, language: name_1.slice(0, 2) };
1157311628
}
1157411629
}
11575-
throw new Error("Not found ".concat(names));
11630+
// throw new Error("Not found ".concat(names));
11631+
// better to continue the app without crashing
11632+
console.error("Not found ".concat(names));
1157611633
}
11634+
1157711635
var globalMessageKeyPrefix = "@";
11636+
1157811637
var globalMessages = Object.fromEntries(Object.entries(getDataByLocale(localeData, "").data).map(function (_a) {
1157911638
var k = _a[0], v = _a[1];
1158011639
return [
@@ -11635,7 +11694,7 @@ var Translator = /** @class */ (function () {
1163511694
}());
1163611695

1163711696
function getI18nObjects(fileData, filterLocales) {
11638-
return getDataByLocale(fileData, "Obj", filterLocales).data;
11697+
return getDataByLocale(fileData, "Obj", filterLocales)?.data;
1163911698
}
1164011699

1164111700
export { AbstractComp, AbstractNode, CachedNode, CodeNode, CompActionTypes, FetchCheckNode, FunctionNode, MultiBaseComp, RecordNode, RelaxedJsonParser, SimpleAbstractComp, SimpleComp, SimpleNode, Translator, ValueAndMsg, WrapContextNodeV2, WrapNode, changeChildAction, changeDependName, changeEditDSLAction, changeValueAction, clearMockWindow, clearStyleEval, customAction, deferAction, deleteCompAction, dependingNodeMapEquals, evalFunc, evalFunctionResult, evalNodeOrMinor, evalPerfUtil, evalScript, evalStyle, executeQueryAction, fromRecord, fromUnevaledValue, fromValue, fromValueWithCache, getDynamicStringSegments, getI18nObjects, getValueByLocale, i18n, isBroadcastAction, isChildAction, isCustomAction, isDynamicSegment, isFetching, isMyCustomAction, mergeExtra, multiChangeAction, nodeIsRecord, onlyEvalAction, relaxedJSONToJSON, renameAction, replaceCompAction, routeByNameAction, transformWrapper, triggerModuleEventAction, unwrapChildAction, updateActionContextAction, updateNodesV2Action, withFunction, wrapActionExtraInfo, wrapChildAction, wrapContext, wrapDispatch };

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

Lines changed: 4 additions & 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 = "de";
6+
const defaultLocale = "en";
77

88
let locales = [defaultLocale];
99

@@ -68,6 +68,9 @@ function getDataByLocale<T>(
6868
filterLocales?: string,
6969
targetLocales?: string[]
7070
) {
71+
72+
console.log("Überraschung", fileData);
73+
7174
let localeInfos = [...fallbackLocaleInfos];
7275

7376
const targetLocaleInfo = parseLocales(targetLocales || []);
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { en } from "./en";
2+
3+
export const de: typeof en = {};

client/packages/lowcoder-core/src/i18n/locales/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
// fallback example: current locale is zh-HK, fallback order is zhHK => zh => en
33
export * from "./en";
44
export * from "./zh";
5+
export * from "./de";
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { en } from "./en";
2+
3+
export const de: typeof en = {...en};

client/packages/lowcoder-design/src/i18n/design/locales/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
// fallback example: current locale is zh-HK, fallback order is zhHK => zh => en
33
export * from "./en";
44
export * from "./zh";
5+
export * from "./de";

client/packages/lowcoder/src/app.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@ class AppIndex extends React.Component<AppIndexProps, any> {
108108
return <ProductLoading hideHeader={hideLoadingHeader} />;
109109
}
110110

111+
// persisting the language in local storage
112+
localStorage.setItem('lowcoder_uiLanguage', this.props.uiLanguage);
113+
111114
return (
112115
<Wrapper language={this.props.uiLanguage}>
113116
<Helmet>

client/packages/lowcoder/src/i18n/LanguageContext.tsx_

Lines changed: 0 additions & 51 deletions
This file was deleted.

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import hr_HR from "antd/es/locale/hr_HR";
2626
import sk_SK from "antd/es/locale/sk_SK";
2727
import sl_SI from "antd/es/locale/sl_SI";
2828
import mk_MK from "antd/es/locale/mk_MK";
29-
29+
import pt_PT from "antd/es/locale/pt_PT";
3030

3131
import { getValueByLocale } from "lowcoder-core";
3232

@@ -57,6 +57,13 @@ function selectAntdLocale(language: string, region?: string) {
5757
default:
5858
return es_ES;
5959
}
60+
case "pt":
61+
switch (region) {
62+
case "PT":
63+
return pt_PT;
64+
default:
65+
return pt_PT;
66+
}
6067
case "fr":
6168
switch (region) {
6269
case "CA":

0 commit comments

Comments
 (0)