Skip to content

Commit ac0ed0d

Browse files
committed
feat(): 框架支持LANGUAGE常量
Closes CMDB_INSTANCE-3369
1 parent fc95fd9 commit ac0ed0d

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

packages/runtime/src/internal/compute/evaluate.spec.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ jest.mock("../devtools.js");
8282

8383
i18n.init({
8484
fallbackLng: "en",
85+
supportedLngs: ["en", "zh"],
8586
});
8687
i18n.addResourceBundle("en", getI18nNamespace("app", "hello"), {
8788
HELLO: "Hello",
@@ -255,6 +256,8 @@ const consoleError = jest.spyOn(console, "error");
255256

256257
describe("evaluate", () => {
257258
beforeEach(() => {
259+
i18n.changeLanguage("zh");
260+
258261
(_internalApiGetRuntimeContext as jest.Mock).mockReset();
259262
});
260263

@@ -291,7 +294,7 @@ describe("evaluate", () => {
291294
["<% I18N('HELLO') %>", "Hello"],
292295
["<% I18N('COUNT_ITEMS', { count: 5 }) %>", "Total 5 items"],
293296
["<% I18N('NOT_EXISTED') %>", "NOT_EXISTED"],
294-
["<% __WIDGET_I18N__('my-widget')('WORLD') %>", "World"],
297+
["<% __WIDGET_I18N__('my-widget')('WORLD') %>", "世界"],
295298
["<% I18N_TEXT({ en: 'hello', zh: '你好' }) %>", "你好"],
296299
["<% CTX.myFreeContext %>", "good"],
297300
["<% CTX.notExisted %>", undefined],
@@ -318,6 +321,7 @@ describe("evaluate", () => {
318321
["<% SIZE %>", 2],
319322
["<% STATE.myState %>", "better"],
320323
["<% FORM_STATE.myFormItem %>", "input"],
324+
["<% LANGUAGE %>", "zh"],
321325
])("evaluate(%j) should return %j", (raw, result) => {
322326
expect(evaluate(raw, runtimeContext)).toEqual(result);
323327
});

packages/runtime/src/internal/compute/getGeneralGlobals.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ function getIndividualGlobal(
8181
);
8282
case "I18N_TEXT":
8383
return collectCoverage ? fakeI18nText : i18nText;
84+
case "LANGUAGE": {
85+
return collectCoverage ? "zh" : i18n.language || "zh";
86+
}
8487
case "PERMISSIONS":
8588
return getReadOnlyProxy({
8689
check: collectCoverage

0 commit comments

Comments
 (0)