Skip to content

Commit fb465c3

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

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

packages/brick-kit/src/internal/evaluate.spec.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ jest.mock("../history", () => ({
6161

6262
i18next.init({
6363
fallbackLng: "en",
64+
supportedLngs: ["en", "zh"],
6465
});
6566
i18next.addResourceBundle("en", "$app-hello", {
6667
HELLO: "Hello",
@@ -224,6 +225,9 @@ describe("shouldDismissRecursiveMarkingInjected", () => {
224225
});
225226

226227
describe("evaluate", () => {
228+
beforeEach(() => {
229+
i18next.changeLanguage("zh");
230+
});
227231
afterEach(() => {
228232
jest.clearAllMocks();
229233
});
@@ -261,7 +265,7 @@ describe("evaluate", () => {
261265
["<% I18N('HELLO') %>", "Hello"],
262266
["<% I18N('COUNT_ITEMS', { count: 5 }) %>", "Total 5 items"],
263267
["<% I18N('NOT_EXISTED') %>", "NOT_EXISTED"],
264-
["<% __WIDGET_I18N__('my-widget')('WORLD') %>", "World"],
268+
["<% __WIDGET_I18N__('my-widget')('WORLD') %>", "世界"],
265269
["<% I18N_TEXT({ en: 'hello', zh: '你好' }) %>", "你好"],
266270
["<% CTX.myFreeContext %>", "good"],
267271
["<% CTX.myPropContext %>", "better"],
@@ -284,6 +288,7 @@ describe("evaluate", () => {
284288
['<% __WIDGET_FN__["widget-a"].abc() %>', "Hello, xyz"],
285289
["<% MISC.hello %>", "world"],
286290
["<% BASE_URL %>", ""],
291+
["<% LANGUAGE %>", "zh"],
287292
])("evaluate(%j) should return %j", (raw, result) => {
288293
expect(evaluate(raw)).toEqual(result);
289294
});

packages/brick-kit/src/internal/evaluate.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import { getCustomTemplateContext } from "../core/CustomTemplates/CustomTemplate
2626
import { getMenu } from "./menu";
2727
import { getMedia } from "./mediaQuery";
2828
import { getCustomFormContext } from "../core/CustomForms/CustomFormContext";
29-
3029
const symbolForRaw = Symbol.for("pre.evaluated.raw");
3130
const symbolForContext = Symbol.for("pre.evaluated.context");
3231

packages/brick-kit/src/internal/getGeneralGlobals.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getFixedT } from "i18next";
1+
import i18next, { getFixedT } from "i18next";
22
import { identity } from "lodash";
33
import type { MicroApp } from "@next-core/brick-types";
44
import { widgetI18nFactory } from "../core/WidgetI18n";
@@ -77,6 +77,9 @@ function getIndividualGlobal(
7777
);
7878
case "I18N_TEXT":
7979
return collectCoverage ? fakeI18nText : i18nText;
80+
case "LANGUAGE": {
81+
return collectCoverage ? "zh" : i18next.language || "zh";
82+
}
8083
case "PERMISSIONS":
8184
return {
8285
check: collectCoverage ? fakeCheckPermissions : checkPermissions,

0 commit comments

Comments
 (0)