Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitdfd3ded

Browse files
authored
Merge pull request#625 from lowcoder-org/feature/translations
Fallback for missing Translation fields
2 parents2476c6f +cb27ed3 commitdfd3ded

File tree

4 files changed

+181
-150
lines changed

4 files changed

+181
-150
lines changed

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

Lines changed: 112 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -9,118 +9,118 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
99

1010
var ___default = /*#__PURE__*/_interopDefaultLegacy(_);
1111

12-
/******************************************************************************
13-
Copyright (c) Microsoft Corporation.
14-
15-
Permission to use, copy, modify, and/or distribute this software for any
16-
purpose with or without fee is hereby granted.
17-
18-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
19-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
20-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
21-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
22-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
23-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
24-
PERFORMANCE OF THIS SOFTWARE.
25-
***************************************************************************** */
26-
/* global Reflect, Promise, SuppressedError, Symbol */
27-
28-
var extendStatics = function(d, b) {
29-
extendStatics = Object.setPrototypeOf ||
30-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
31-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
32-
return extendStatics(d, b);
33-
};
34-
35-
function __extends(d, b) {
36-
if (typeof b !== "function" && b !== null)
37-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
38-
extendStatics(d, b);
39-
function __() { this.constructor = d; }
40-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
41-
}
42-
43-
var __assign = function() {
44-
__assign = Object.assign || function __assign(t) {
45-
for (var s, i = 1, n = arguments.length; i < n; i++) {
46-
s = arguments[i];
47-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
48-
}
49-
return t;
50-
};
51-
return __assign.apply(this, arguments);
52-
};
53-
54-
function __rest(s, e) {
55-
var t = {};
56-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
57-
t[p] = s[p];
58-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
59-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
60-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
61-
t[p[i]] = s[p[i]];
62-
}
63-
return t;
64-
}
65-
66-
function __decorate(decorators, target, key, desc) {
67-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
68-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
69-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
70-
return c > 3 && r && Object.defineProperty(target, key, r), r;
71-
}
72-
73-
function __awaiter(thisArg, _arguments, P, generator) {
74-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
75-
return new (P || (P = Promise))(function (resolve, reject) {
76-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
77-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
78-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
79-
step((generator = generator.apply(thisArg, _arguments || [])).next());
80-
});
81-
}
82-
83-
function __generator(thisArg, body) {
84-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
85-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
86-
function verb(n) { return function (v) { return step([n, v]); }; }
87-
function step(op) {
88-
if (f) throw new TypeError("Generator is already executing.");
89-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
90-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
91-
if (y = 0, t) op = [op[0] & 2, t.value];
92-
switch (op[0]) {
93-
case 0: case 1: t = op; break;
94-
case 4: _.label++; return { value: op[1], done: false };
95-
case 5: _.label++; y = op[1]; op = [0]; continue;
96-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
97-
default:
98-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
99-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
100-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
101-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
102-
if (t[2]) _.ops.pop();
103-
_.trys.pop(); continue;
104-
}
105-
op = body.call(thisArg, _);
106-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
107-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
108-
}
109-
}
110-
111-
function __spreadArray(to, from, pack) {
112-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
113-
if (ar || !(i in from)) {
114-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
115-
ar[i] = from[i];
116-
}
117-
}
118-
return to.concat(ar || Array.prototype.slice.call(from));
119-
}
120-
121-
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
122-
var e = new Error(message);
123-
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
12+
/******************************************************************************
13+
Copyright (c) Microsoft Corporation.
14+
15+
Permission to use, copy, modify, and/or distribute this software for any
16+
purpose with or without fee is hereby granted.
17+
18+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
19+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
20+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
21+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
22+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
23+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
24+
PERFORMANCE OF THIS SOFTWARE.
25+
***************************************************************************** */
26+
/* global Reflect, Promise, SuppressedError, Symbol */
27+
28+
var extendStatics = function(d, b) {
29+
extendStatics = Object.setPrototypeOf ||
30+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
31+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
32+
return extendStatics(d, b);
33+
};
34+
35+
function __extends(d, b) {
36+
if (typeof b !== "function" && b !== null)
37+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
38+
extendStatics(d, b);
39+
function __() { this.constructor = d; }
40+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
41+
}
42+
43+
var __assign = function() {
44+
__assign = Object.assign || function __assign(t) {
45+
for (var s, i = 1, n = arguments.length; i < n; i++) {
46+
s = arguments[i];
47+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
48+
}
49+
return t;
50+
};
51+
return __assign.apply(this, arguments);
52+
};
53+
54+
function __rest(s, e) {
55+
var t = {};
56+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
57+
t[p] = s[p];
58+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
59+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
60+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
61+
t[p[i]] = s[p[i]];
62+
}
63+
return t;
64+
}
65+
66+
function __decorate(decorators, target, key, desc) {
67+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
68+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
69+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
70+
return c > 3 && r && Object.defineProperty(target, key, r), r;
71+
}
72+
73+
function __awaiter(thisArg, _arguments, P, generator) {
74+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
75+
return new (P || (P = Promise))(function (resolve, reject) {
76+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
77+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
78+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
79+
step((generator = generator.apply(thisArg, _arguments || [])).next());
80+
});
81+
}
82+
83+
function __generator(thisArg, body) {
84+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
85+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
86+
function verb(n) { return function (v) { return step([n, v]); }; }
87+
function step(op) {
88+
if (f) throw new TypeError("Generator is already executing.");
89+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
90+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
91+
if (y = 0, t) op = [op[0] & 2, t.value];
92+
switch (op[0]) {
93+
case 0: case 1: t = op; break;
94+
case 4: _.label++; return { value: op[1], done: false };
95+
case 5: _.label++; y = op[1]; op = [0]; continue;
96+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
97+
default:
98+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
99+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
100+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
101+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
102+
if (t[2]) _.ops.pop();
103+
_.trys.pop(); continue;
104+
}
105+
op = body.call(thisArg, _);
106+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
107+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
108+
}
109+
}
110+
111+
function __spreadArray(to, from, pack) {
112+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
113+
if (ar || !(i in from)) {
114+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
115+
ar[i] = from[i];
116+
}
117+
}
118+
return to.concat(ar || Array.prototype.slice.call(from));
119+
}
120+
121+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
122+
var e = new Error(message);
123+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
124124
};
125125

126126
function isEqualArgs(args, cacheArgs, equals) {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -659,6 +659,7 @@ type AddPrefix<T, P extends string> = {
659659
declareconstglobalMessages:AddPrefix<{},"@">;
660660
typeGlobalMessageKey=NestedKey<typeofglobalMessages>;
661661
typeVariableValue=string|number|boolean|Date|React.ReactNode;
662+
662663
declareclassTranslator<Messagesextendsobject>{
663664
privatereadonlymessages;
664665
readonlylanguage:string;

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

Lines changed: 50 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -11583,40 +11583,57 @@ var globalMessages = Object.fromEntries(Object.entries(getDataByLocale(localeDat
1158311583
];
1158411584
}));
1158511585
var Translator = /** @class */ (function () {
11586-
function Translator(fileData, filterLocales, locales) {
11587-
var _a = getDataByLocale(fileData, "", filterLocales, locales), data = _a.data, language = _a.language;
11588-
this.messages = Object.assign({}, data, globalMessages);
11589-
this.language = language;
11590-
this.trans = this.trans.bind(this);
11591-
this.transToNode = this.transToNode.bind(this);
11592-
}
11593-
Translator.prototype.trans = function (key, variables) {
11594-
return this.transToNode(key, variables).toString();
11595-
};
11596-
Translator.prototype.transToNode = function (key, variables) {
11597-
var message = this.getMessage(key);
11598-
var node = new IntlMessageFormat(message, i18n.locale).format(variables);
11599-
if (Array.isArray(node)) {
11600-
return node.map(function (n, i) { return jsxRuntimeExports.jsx(reactExports.Fragment, { children: n }, i); });
11601-
}
11602-
return node;
11603-
};
11604-
Translator.prototype.getMessage = function (key) {
11605-
var value = this.messages[key];
11606-
if (value !== undefined) {
11607-
return value;
11608-
}
11609-
var obj = this.messages;
11610-
for (var _i = 0, _a = key.split("."); _i < _a.length; _i++) {
11611-
var k = _a[_i];
11612-
if (obj !== undefined) {
11613-
obj = obj[k];
11614-
}
11615-
}
11616-
return obj;
11617-
};
11618-
return Translator;
11586+
function Translator(fileData, filterLocales, locales) {
11587+
var _a = getDataByLocale(fileData, "", filterLocales, locales), data = _a.data, language = _a.language;
11588+
this.messages = Object.assign({}, data, globalMessages);
11589+
this.language = language;
11590+
this.trans = this.trans.bind(this);
11591+
this.transToNode = this.transToNode.bind(this);
11592+
}
11593+
11594+
Translator.prototype.trans = function (key, variables) {
11595+
return this.transToNode(key, variables).toString();
11596+
};
11597+
11598+
Translator.prototype.transToNode = function (key, variables) {
11599+
var message = this.getMessage(key);
11600+
var node = new IntlMessageFormat(message, i18n.locale).format(variables);
11601+
if (Array.isArray(node)) {
11602+
return node.map(function (n, i) { return jsxRuntimeExports.jsx(reactExports.Fragment, { children: n }, i); });
11603+
}
11604+
return node;
11605+
};
11606+
11607+
Translator.prototype.getMessage = function (key) {
11608+
var value = this.getNestedMessage(this.messages, key);
11609+
11610+
// Fallback to English if the message is not found
11611+
if (value === undefined) {
11612+
value = this.getNestedMessage(localeData.en, key); // Assuming localeData.en contains English translations
11613+
}
11614+
11615+
// If still not found, return a default message or the key itself
11616+
if (value === undefined) {
11617+
console.warn(`Translation missing for key: ${key}`);
11618+
return `oups! ${key}`; // or simply return the key
11619+
}
11620+
11621+
return value;
11622+
};
11623+
11624+
Translator.prototype.getNestedMessage = function (obj, key) {
11625+
for (var _i = 0, _a = key.split("."); _i < _a.length; _i++) {
11626+
var k = _a[_i];
11627+
if (obj !== undefined) {
11628+
obj = obj[k];
11629+
}
11630+
}
11631+
return obj;
11632+
};
11633+
11634+
return Translator;
1161911635
}());
11636+
1162011637
function getI18nObjects(fileData, filterLocales) {
1162111638
return getDataByLocale(fileData, "Obj", filterLocales).data;
1162211639
}

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

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -159,18 +159,31 @@ export class Translator<Messages extends object> {
159159
}
160160

161161
privategetMessage(key:NestedKey<Messages>|GlobalMessageKey){
162-
constvalue=this.messages[key];
163-
if(value!==undefined){
164-
returnvalue;
162+
letmessage=this.getNestedMessage(this.messages,key);
163+
164+
// Fallback to English if the message is not found
165+
if(message===undefined){
166+
message=this.getNestedMessage(localeData.en,key);// Assuming localeData.en contains English translations
165167
}
166-
letobj:any=this.messages;
167-
for(constkof(keyasstring).split(".")){
168+
169+
// If still not found, return a default message or the key itself
170+
if(message===undefined){
171+
console.warn(`Translation missing for key:${key}`);
172+
`oups!${key}`;
173+
}
174+
175+
returnmessage;
176+
}
177+
178+
privategetNestedMessage(obj:any,key:string){
179+
for(constkofkey.split(".")){
168180
if(obj!==undefined){
169181
obj=obj[k];
170182
}
171183
}
172184
returnobj;
173185
}
186+
174187
}
175188

176189
exportfunctiongetI18nObjects<I18nObjects>(fileData:object,filterLocales?:string){

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp