UNPKG

@scaleway/use-i18n

Version:
7 lines (6 loc) 1.02 kB
import type { BaseLocale, LocaleKeys, LocaleValue, Params, Scopes } from 'international-types'; import type { ReactNode } from 'react'; export type ScopedValue<Locale extends BaseLocale, Scope extends Scopes<Locale> | undefined, Key extends LocaleKeys<Locale, Scope>> = Scope extends undefined ? Locale[Key] : Locale[`${Scope}.${Key}`]; export type ReactParamsObject<Value extends LocaleValue> = Record<Params<Value>[number], LocaleValue | ReactNode>; export type TranslateFn<Locale extends BaseLocale> = <Key extends LocaleKeys<Locale, undefined>, Value extends LocaleValue = ScopedValue<Locale, undefined, Key>>(key: Key, ...params: Params<Value>['length'] extends 0 ? [] : [ReactParamsObject<Value>]) => string; export type ScopedTranslateFn<Locale extends BaseLocale> = <Scope extends Scopes<Locale>>(scope: Scope) => <Key extends LocaleKeys<Locale, Scope>, Value extends LocaleValue = ScopedValue<Locale, Scope, Key>>(key: Key, ...params: Params<Value>['length'] extends 0 ? [] : [ReactParamsObject<Value>]) => string;