mirror of
https://github.com/alibaba/lowcode-engine.git
synced 2025-12-10 18:03:01 +00:00
feat(common): add common.utils.intl API
This commit is contained in:
parent
a00c5c9b60
commit
a7d3996fa2
@ -145,6 +145,22 @@ const { intl, getLocale, setLocale } = common.utils.createIntl({
|
||||
|
||||
```
|
||||
|
||||
#### intl
|
||||
|
||||
i18n 转换方法
|
||||
|
||||
```typescript
|
||||
/**
|
||||
* i18n 转换方法
|
||||
*/
|
||||
intl(data: IPublicTypeI18nData | string, params?: object): string;
|
||||
```
|
||||
|
||||
##### 示例
|
||||
```
|
||||
const title = common.utils.intl(node.title)
|
||||
```
|
||||
|
||||
### skeletonCabin
|
||||
#### Workbench
|
||||
编辑器框架 View
|
||||
|
||||
@ -3,6 +3,7 @@ import { IntlMessageFormat } from 'intl-messageformat';
|
||||
import { globalLocale } from './global-locale';
|
||||
import { isI18nData } from '@alilc/lowcode-utils';
|
||||
import { observer } from '../utils';
|
||||
import { IPublicTypeI18nData } from '@alilc/lowcode-types';
|
||||
|
||||
function generateTryLocales(locale: string) {
|
||||
const tries = [locale, locale.replace('-', '_')];
|
||||
@ -26,18 +27,9 @@ function injectVars(msg: string, params: any, locale: string): string {
|
||||
}
|
||||
const formater = new IntlMessageFormat(msg, locale);
|
||||
return formater.format(params as any) as string;
|
||||
/*
|
||||
|
||||
return template.replace(/({\w+})/g, (_, $1) => {
|
||||
const key = (/\d+/.exec($1) || [])[0] as any;
|
||||
if (key && params[key] != null) {
|
||||
return params[key];
|
||||
}
|
||||
return $1;
|
||||
}); */
|
||||
}
|
||||
|
||||
export function intl(data: any, params?: object): ReactNode {
|
||||
export function intl(data: IPublicTypeI18nData | string, params?: object): ReactNode {
|
||||
if (!isI18nData(data)) {
|
||||
return data;
|
||||
}
|
||||
|
||||
@ -26,6 +26,7 @@ import {
|
||||
IPublicApiCommonEditorCabin,
|
||||
IPublicModelDragon,
|
||||
IPublicModelSettingField,
|
||||
IPublicTypeI18nData,
|
||||
} from '@alilc/lowcode-types';
|
||||
import {
|
||||
SettingField as InnerSettingField,
|
||||
@ -261,6 +262,10 @@ class Utils implements IPublicApiCommonUtils {
|
||||
} {
|
||||
return innerCreateIntl(instance);
|
||||
}
|
||||
|
||||
intl(data: IPublicTypeI18nData | string, params?: object): any {
|
||||
return innerIntl(data, params);
|
||||
}
|
||||
}
|
||||
|
||||
class EditorCabin implements IPublicApiCommonEditorCabin {
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
|
||||
import { Component, ReactNode } from 'react';
|
||||
import { IPublicTypeNodeSchema, IPublicTypeTitleContent } from '../type';
|
||||
import { IPublicTypeI18nData, IPublicTypeNodeSchema, IPublicTypeTitleContent } from '../type';
|
||||
import { IPublicEnumTransitionType } from '../enum';
|
||||
|
||||
export interface IPublicApiCommonUtils {
|
||||
@ -69,6 +69,11 @@ export interface IPublicApiCommonUtils {
|
||||
getLocale(): string;
|
||||
setLocale(locale: string): void;
|
||||
};
|
||||
|
||||
/**
|
||||
* i18n 转换方法
|
||||
*/
|
||||
intl(data: IPublicTypeI18nData | string, params?: object): string;
|
||||
}
|
||||
export interface IPublicApiCommonSkeletonCabin {
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user