mk-tsx-i18n
v1.0.0
Published
i18n for tsx
Downloads
2
Readme
React-tsx-i18n 语言包
import { I18n, I18nArgs, NotUnJSXObject, RetureI18nType, TI18nKeyType } from 'react-tsx-i18n';
const zhCn = { a: { title: '标题' } };
const enUs = { a: { title: 'title' } };
type TLanguage = typeof zhCn | typeof enUs;
const all = {
zhCn, enUs
};
/**
* all 所有语言包
* zhCn 当前语言包
* @params jsx 允许插入jsx代码
*
*/
const i18n = I18n.create(all, 'zhCn', (jsx)=><>{jsx}</>);
export language = i18n.language;
export const translate = <T extends I18nArgs = unknow>(
key: TKeys, ...args: NotUnJSXObject<T>[]
): ReturnI18nType<T> => i18n.translator(key, ...args);
export const replace = <T extends I18nArgs = unknow>(
key: string, ...args: NotUnJSXObject<T>[]
): ReturnI18nType<T> => i18n.replace(key, ...args);
import { translate, replace, language } from './local';
translate('a.title', '我是标题');
translate('a.title', 1);
translate('a.title', <span>我是标题</span>);
replace(language.a.title, '我是标题');
replace(language.a.title, 1);
replace(language.a.title, <span>我是标题</span>);