GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat(common): add common.utils.intl API · czfadmin/lowcode-engine@a7d3996

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • docs/docs/api
    • common.md
  • packages
    • editor-core/src/intl
      • index.ts
    • shell/src/api
      • common.tsx
    • types/src/shell/api
      • common.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎docs/docs/api/common.md‎

Copy file name to clipboardExpand all lines: docs/docs/api/common.md
+16Lines changed: 16 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,22 @@ const { intl, getLocale, setLocale } = common.utils.createIntl({
145145

146146
```
147147

148+
#### intl
149+
150+
i18n 转换方法
151+
152+
```typescript
153+
/**
154+
* i18n 转换方法
155+
*/
156+
intl(data: IPublicTypeI18nData | string, params?: object): string;
157+
```
158+
159+
##### 示例
160+
```
161+
const title = common.utils.intl(node.title)
162+
```
163+
148164
### skeletonCabin
149165
#### Workbench
150166
编辑器框架 View
Collapse file

‎packages/editor-core/src/intl/index.ts‎

Copy file name to clipboardExpand all lines: packages/editor-core/src/intl/index.ts
+2-10Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { IntlMessageFormat } from 'intl-messageformat';
33
import { globalLocale } from './global-locale';
44
import { isI18nData } from '@alilc/lowcode-utils';
55
import { observer } from '../utils';
6+
import { IPublicTypeI18nData } from '@alilc/lowcode-types';
67

78
function generateTryLocales(locale: string) {
89
const tries = [locale, locale.replace('-', '_')];
@@ -26,18 +27,9 @@ function injectVars(msg: string, params: any, locale: string): string {
2627
}
2728
const formater = new IntlMessageFormat(msg, locale);
2829
return formater.format(params as any) as string;
29-
/*
30-
31-
return template.replace(/({\w+})/g, (_, $1) => {
32-
const key = (/\d+/.exec($1) || [])[0] as any;
33-
if (key && params[key] != null) {
34-
return params[key];
35-
}
36-
return $1;
37-
}); */
3830
}
3931

40-
export function intl(data: any, params?: object): ReactNode {
32+
export function intl(data: IPublicTypeI18nData | string, params?: object): ReactNode {
4133
if (!isI18nData(data)) {
4234
return data;
4335
}
Collapse file

‎packages/shell/src/api/common.tsx‎

Copy file name to clipboardExpand all lines: packages/shell/src/api/common.tsx
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import {
2626
IPublicApiCommonEditorCabin,
2727
IPublicModelDragon,
2828
IPublicModelSettingField,
29+
IPublicTypeI18nData,
2930
} from '@alilc/lowcode-types';
3031
import {
3132
SettingField as InnerSettingField,
@@ -261,6 +262,10 @@ class Utils implements IPublicApiCommonUtils {
261262
} {
262263
return innerCreateIntl(instance);
263264
}
265+
266+
intl(data: IPublicTypeI18nData | string, params?: object): any {
267+
return innerIntl(data, params);
268+
}
264269
}
265270

266271
class EditorCabin implements IPublicApiCommonEditorCabin {
Collapse file

‎packages/types/src/shell/api/common.ts‎

Copy file name to clipboardExpand all lines: packages/types/src/shell/api/common.ts
+6-1Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
import { Component, ReactNode } from 'react';
3-
import { IPublicTypeNodeSchema, IPublicTypeTitleContent } from '../type';
3+
import { IPublicTypeI18nData, IPublicTypeNodeSchema, IPublicTypeTitleContent } from '../type';
44
import { IPublicEnumTransitionType } from '../enum';
55

66
export interface IPublicApiCommonUtils {
@@ -69,6 +69,11 @@ export interface IPublicApiCommonUtils {
6969
getLocale(): string;
7070
setLocale(locale: string): void;
7171
};
72+
73+
/**
74+
* i18n 转换方法
75+
*/
76+
intl(data: IPublicTypeI18nData | string, params?: object): string;
7277
}
7378
export interface IPublicApiCommonSkeletonCabin {
7479

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.