Skip to content

Translation & User-Profile #830

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 10 commits into from
Apr 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,4 @@ You can access Lowcoder from [cloud-hosted version](https://app.lowcoder.cloud/)
Accelerate the growth of Lowcoder and unleash its potential with your Sponsorship – together, we're shaping the future of Lowcode for everyone!
[Be a Sponsor](https://github.com/sponsors/lowcoder-org)

Like ... [@spacegoats-io](https://github.com/spacegoats-io), [@Jomedya](https://github.com/Jomedya), [@CHSchuepfer](https://github.com/CHSchuepfer), Thank you very much!!
Like ... [@Darkjamin](https://github.com/Darkjamin), [@spacegoats-io](https://github.com/spacegoats-io), [@Jomedya](https://github.com/Jomedya), [@CHSchuepfer](https://github.com/CHSchuepfer), Thank you very much!!
2 changes: 2 additions & 0 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@
"@types/styled-components": "^5.1.34",
"antd-mobile": "^5.34.0",
"chalk": "4",
"flag-icons": "^7.2.1",
"number-precision": "^1.6.0",
"react-countup": "^6.5.3",
"react-player": "^2.11.0",
"resize-observer-polyfill": "^1.5.1",
"rollup": "^4.13.0",
Expand Down
2 changes: 2 additions & 0 deletions client/packages/lowcoder-core/lib/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -11513,6 +11513,7 @@ var IntlMessageFormat = IntlMessageFormat$1;

var defaultLocale = "en";
var locales = [defaultLocale];

if (globalThis.navigator) {
if (navigator.languages && navigator.languages.length > 0) {
locales = __spreadArray([], navigator.languages, true);
Expand All @@ -11521,6 +11522,7 @@ if (globalThis.navigator) {
locales = [navigator.language || navigator.userLanguage || defaultLocale];
}
}

function parseLocale(s) {
var locale = s.trim();
if (!locale) {
Expand Down
3 changes: 3 additions & 0 deletions client/packages/lowcoder-core/lib/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,9 @@ declare const i18n: {
region?: string | undefined;
locales: string[];
};

declare function getValueByLocale<T>(defaultValue: T, func: (info: LocaleInfo) => T | undefined): T;

type AddDot<T extends string> = T extends "" ? "" : `.${T}`;
type ValidKey<T> = Exclude<keyof T, symbol>;
type NestedKey<T> = (T extends object ? {
Expand All @@ -658,6 +660,7 @@ type AddPrefix<T, P extends string> = {
[K in keyof T as K extends string ? `${P}${K}` : never]: T[K];
};
declare const globalMessages: AddPrefix<{}, "@">;

type GlobalMessageKey = NestedKey<typeof globalMessages>;
type VariableValue = string | number | boolean | Date | React.ReactNode;

Expand Down
69 changes: 64 additions & 5 deletions client/packages/lowcoder-core/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7581,15 +7581,62 @@ function requireReactJsxRuntime_development () {
} (jsxRuntime));

var en = {};

var zh = {};
var de = {};
var fr = {};
var es = {};
var it = {};
var ar = {};
var th = {};
var vi = {};
var ms = {};
var id = {};
var hi = {};
var ta = {};
var kn = {};
var ml = {};
var ru = {};
var pl = {};
var cs = {};
var uk = {};
var bg = {};
var sr = {};
var hr = {};
var sk = {};
var sl = {};
var mk = {};
var pt = {};

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

var localeData = /*#__PURE__*/Object.freeze({
__proto__: null,
en: en,
zh: zh
zh: zh,
de: de,
fr: fr,
es: es,
it: it,
ar: ar,
th: th,
vi: vi,
ms: ms,
id: id,
hi: hi,
ta: ta,
kn: kn,
ml: ml,
ru: ru,
pl: pl,
cs: cs,
uk: uk,
bg: bg,
sr: sr,
hr: hr,
sk: sk,
sl: sl,
mk: mk,
pt: pt
});

var ErrorKind;
Expand Down Expand Up @@ -11505,14 +11552,22 @@ var IntlMessageFormat = IntlMessageFormat$1;

var defaultLocale = "en";
var locales = [defaultLocale];

// Falk - Adapted the central translator to check if a localStorage key is existing.

const uiLanguage = localStorage.getItem('lowcoder_uiLanguage');
if (globalThis.navigator) {
if (navigator.languages && navigator.languages.length > 0) {
if (uiLanguage) {
locales = [uiLanguage];
}
else if (navigator.languages && navigator.languages.length > 0) {
locales = __spreadArray([], navigator.languages, true);
}
else {
locales = [navigator.language || navigator.userLanguage || defaultLocale];
}
}

function parseLocale(s) {
var locale = s.trim();
if (!locale) {
Expand Down Expand Up @@ -11572,9 +11627,13 @@ function getDataByLocale(fileData, suffix, filterLocales, targetLocales) {
return { data: data, language: name_1.slice(0, 2) };
}
}
throw new Error("Not found ".concat(names));
// throw new Error("Not found ".concat(names));
// better to continue the app without crashing
console.error("Not found ".concat(names));
}

var globalMessageKeyPrefix = "@";

var globalMessages = Object.fromEntries(Object.entries(getDataByLocale(localeData, "").data).map(function (_a) {
var k = _a[0], v = _a[1];
return [
Expand Down Expand Up @@ -11635,7 +11694,7 @@ var Translator = /** @class */ (function () {
}());

function getI18nObjects(fileData, filterLocales) {
return getDataByLocale(fileData, "Obj", filterLocales).data;
return getDataByLocale(fileData, "Obj", filterLocales)?.data;
}

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 };
3 changes: 3 additions & 0 deletions client/packages/lowcoder-core/src/i18n/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ function getDataByLocale<T>(
filterLocales?: string,
targetLocales?: string[]
) {

console.log("Überraschung", fileData);

let localeInfos = [...fallbackLocaleInfos];

const targetLocaleInfo = parseLocales(targetLocales || []);
Expand Down
3 changes: 3 additions & 0 deletions client/packages/lowcoder-core/src/i18n/locales/de.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { en } from "./en";

export const de: typeof en = {};
1 change: 1 addition & 0 deletions client/packages/lowcoder-core/src/i18n/locales/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
// fallback example: current locale is zh-HK, fallback order is zhHK => zh => en
export * from "./en";
export * from "./zh";
export * from "./de";
3 changes: 3 additions & 0 deletions client/packages/lowcoder-design/src/i18n/design/locales/de.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { en } from "./en";

export const de: typeof en = {...en};
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
// fallback example: current locale is zh-HK, fallback order is zhHK => zh => en
export * from "./en";
export * from "./zh";
export * from "./de";
Loading
Loading