UNPKG

@voerkai18n/react

Version:

React支持,提供语言切换等功能

72 lines (66 loc) 2.58 kB
import * as _voerkai18n_runtime from '@voerkai18n/runtime'; import { VoerkaI18nTranslateProps, VoerkaI18nTranslateComponentBuilder, VoerkaI18nScope, VoerkaI18nManager } from '@voerkai18n/runtime'; import React$1 from 'react'; import * as react_jsx_runtime from 'react/jsx-runtime'; /** * * 翻译组件 * * import { createTranslateComponent } from '@voerkai18n/react' * * const scope = new VoerkaI18nScope({ * component: createTranslateComponent(({message,vars,options,language})=>{ * return <span>{message}</span> * }, * { * loading: <Loading/> // 自定义加载中组件 * default: "" // 默认文本 * } * }) * * <Translate message="I am {}" vars={['fisher']} options={{...}} /> * * <Translate * message={ * async (language,vars,options)=>{ * const remoteMessage = await fetch(`https://example.com/api/translate?language=${language}&message=1001`).then((res)=>res.text()) * return remoteMessage // = "I am {}" * } * } * default="I am {}" * vars={['fisher']} * options={{...}} // 传递给翻译器的参数 * /> * * <Translate id="aaa"> * 段落内容 * </Translate> * */ type CreateTranslateComponentOptions = { tagName?: string; attrs?: Record<string, string>; class?: string; style?: React$1.CSSProperties; loading?: React$1.ReactNode; }; type ReactTranslateComponentType = React$1.FC<VoerkaI18nTranslateProps>; type VoerkaI18nReactTranslateComponentBuilder = VoerkaI18nTranslateComponentBuilder<ReactTranslateComponentType>; declare function createTranslateComponent(options?: CreateTranslateComponentOptions): VoerkaI18nReactTranslateComponentBuilder; declare function useVoerkaI18n(scope?: VoerkaI18nScope): { scope: VoerkaI18nScope<any, any>; manager: VoerkaI18nManager; activeLanguage: string; defaultLanguage: string; languages: _voerkai18n_runtime.VoerkaI18nLanguage[]; changeLanguage: (language: string) => Promise<string>; t: _voerkai18n_runtime.VoerkaI18nTranslate<string>; }; /** * */ type VoerkaI18nProviderProps = React.PropsWithChildren<{ fallback?: React.ReactNode; }>; declare function VoerkaI18nProvider(props: VoerkaI18nProviderProps): react_jsx_runtime.JSX.Element; export { type CreateTranslateComponentOptions, type ReactTranslateComponentType, VoerkaI18nProvider, type VoerkaI18nProviderProps, type VoerkaI18nReactTranslateComponentBuilder, createTranslateComponent, useVoerkaI18n };