UNPKG

@ices/react-locale

Version:
59 lines (58 loc) 2.77 kB
import { Context } from 'react'; import { MessageDefinitions, PluginFunction, TranslateFunction } from './message'; import { LocaleResourceLoader, setLocale as setContextLocale } from './context'; /** * useTrans 或 useContextTrans 的返回值类型。 */ export declare type UseTransResponse = [ /** * 转译函数。用于获取转译后的消息内容。 */ TranslateFunction, /** * 当前已应用的区域语言值。 */ string, /** * 用于变更当前区域语言设置。 */ typeof setContextLocale ]; /** * useTrans 函数的类型定义。 */ export declare type UseTransType = ReturnType<typeof withDefinitionsHook>; /** * UseContextTrans 函数的类型定义。 */ export declare type UseContextTransType = ReturnType<typeof withDefinitionsContextHook>; /** * 使用绑定了上下文组件的本地化消息hook。 * @param contextType 上下文组件。 * @param plugins 插件函数,或包含插件函数的数组。 * @param fallback 当前区域语言没有匹配到相关定义时,备选的区域语言。默认值为默认的区域语言设置。 * @param definitions 区域语言内容定义。 */ export declare function useContextLocaleTrans(contextType: Context<string>, plugins?: PluginFunction | PluginFunction[] | null, fallback?: string, definitions?: MessageDefinitions | LocaleResourceLoader): UseTransResponse; /** * 使用本地化消息hook。 * @param plugins 插件函数,或包含插件函数的数组。 * @param fallback 当前区域语言没有匹配到相关定义时,备选的区域语言。默认值为默认的区域语言设置。 * @param definitions 区域语言内容定义。 */ export declare function useLocaleTrans(plugins?: PluginFunction | PluginFunction[] | null, fallback?: string, definitions?: MessageDefinitions | LocaleResourceLoader): UseTransResponse; /** * 绑定消息定义对象的 useTrans hook。 * @param definitions 消息定义对象。 */ export declare function withDefinitionsHook(definitions?: MessageDefinitions | LocaleResourceLoader): { (plugins: PluginFunction | PluginFunction[] | null, initialLocale: string | (() => string), initialFallback: string): UseTransResponse; (plugins: PluginFunction | PluginFunction[] | null, fallback: string): UseTransResponse; (plugins: PluginFunction | PluginFunction[] | null): UseTransResponse; (): UseTransResponse; }; /** * 绑定消息定义对象的 useContextTrans hook。 * @param definitions 消息定义对象。 */ export declare function withDefinitionsContextHook(definitions?: MessageDefinitions | LocaleResourceLoader): (contextType: Context<string>, plugins?: PluginFunction | PluginFunction[] | null, fallback?: string) => UseTransResponse;