GeezerVison is showing github.com — feat(common): add common.utils.intl API · czfadmin/lowcode-engine@a7d3996
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file 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 number | Diff line number | Diff line change |
|---|
@@ -145,6 +145,22 @@ const { intl, getLocale, setLocale } = common.utils.createIntl({ | 145 | 145 |
| 146 | 146 | ``` | 147 | 147 |
| | 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 | + | 148 | 164 | ### skeletonCabin | 149 | 165 | #### Workbench | 150 | 166 | 编辑器框架 View | |
Collapse file Copy file name to clipboardExpand all lines: packages/editor-core/src/intl/index.ts +2-10Lines changed: 2 additions & 10 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -3,6 +3,7 @@ import { IntlMessageFormat } from 'intl-messageformat'; | 3 | 3 | import { globalLocale } from './global-locale'; | 4 | 4 | import { isI18nData } from '@alilc/lowcode-utils'; | 5 | 5 | import { observer } from '../utils'; | | 6 | +import { IPublicTypeI18nData } from '@alilc/lowcode-types'; | 6 | 7 |
| 7 | 8 | function generateTryLocales(locale: string) { | 8 | 9 | const tries = [locale, locale.replace('-', '_')]; | @@ -26,18 +27,9 @@ function injectVars(msg: string, params: any, locale: string): string { | 26 | 27 | } | 27 | 28 | const formater = new IntlMessageFormat(msg, locale); | 28 | 29 | 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 | | - }); */ | 38 | 30 | } | 39 | 31 |
| 40 | | -export function intl(data: any, params?: object): ReactNode { | | 32 | +export function intl(data: IPublicTypeI18nData | string, params?: object): ReactNode { | 41 | 33 | if (!isI18nData(data)) { | 42 | 34 | return data; | 43 | 35 | } | |
Collapse file Copy file name to clipboardExpand all lines: packages/shell/src/api/common.tsx +5Lines changed: 5 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -26,6 +26,7 @@ import { | 26 | 26 | IPublicApiCommonEditorCabin, | 27 | 27 | IPublicModelDragon, | 28 | 28 | IPublicModelSettingField, | | 29 | + IPublicTypeI18nData, | 29 | 30 | } from '@alilc/lowcode-types'; | 30 | 31 | import { | 31 | 32 | SettingField as InnerSettingField, | @@ -261,6 +262,10 @@ class Utils implements IPublicApiCommonUtils { | 261 | 262 | } { | 262 | 263 | return innerCreateIntl(instance); | 263 | 264 | } | | 265 | + | | 266 | + intl(data: IPublicTypeI18nData | string, params?: object): any { | | 267 | + return innerIntl(data, params); | | 268 | + } | 264 | 269 | } | 265 | 270 |
| 266 | 271 | class EditorCabin implements IPublicApiCommonEditorCabin { | |
Collapse file Copy file name to clipboardExpand all lines: packages/types/src/shell/api/common.ts +6-1Lines changed: 6 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 |
| 2 | 2 | import { Component, ReactNode } from 'react'; | 3 | | -import { IPublicTypeNodeSchema, IPublicTypeTitleContent } from '../type'; | | 3 | +import { IPublicTypeI18nData, IPublicTypeNodeSchema, IPublicTypeTitleContent } from '../type'; | 4 | 4 | import { IPublicEnumTransitionType } from '../enum'; | 5 | 5 |
| 6 | 6 | export interface IPublicApiCommonUtils { | @@ -69,6 +69,11 @@ export interface IPublicApiCommonUtils { | 69 | 69 | getLocale(): string; | 70 | 70 | setLocale(locale: string): void; | 71 | 71 | }; | | 72 | + | | 73 | + /** | | 74 | + * i18n 转换方法 | | 75 | + */ | | 76 | + intl(data: IPublicTypeI18nData | string, params?: object): string; | 72 | 77 | } | 73 | 78 | export interface IPublicApiCommonSkeletonCabin { | 74 | 79 |
| |
|