|
|
|
import type { $Dictionary, $NormalizeIntoArray } from './typescript/helpers.js'; |
|
import type { |
|
DefaultNamespace, |
|
FlatNamespace, |
|
FormatFunction, |
|
InitOptions, |
|
InterpolationOptions, |
|
Namespace, |
|
Resource, |
|
ResourceKey, |
|
ResourceLanguage, |
|
TOptions, |
|
} from './typescript/options.js'; |
|
import type { KeyPrefix, TFunction } from './typescript/t.js'; |
|
|
|
export interface WithT<Ns extends Namespace = DefaultNamespace> { |
|
|
|
t: TFunction<Ns>; |
|
} |
|
|
|
export interface Interpolator { |
|
init(options: InterpolationOptions, reset: boolean): undefined; |
|
reset(): undefined; |
|
resetRegExp(): undefined; |
|
interpolate(str: string, data: object, lng: string, options: InterpolationOptions): string; |
|
nest(str: string, fc: (...args: any[]) => any, options: InterpolationOptions): string; |
|
} |
|
|
|
export class ResourceStore { |
|
constructor(data: Resource, options: InitOptions); |
|
|
|
public data: Resource; |
|
|
|
public options: InitOptions; |
|
|
|
|
|
|
|
|
|
on(event: 'added' | 'removed', callback: (lng: string, ns: string) => void): void; |
|
|
|
|
|
|
|
|
|
|
|
off(event: 'added' | 'removed', callback?: (lng: string, ns: string) => void): void; |
|
} |
|
|
|
export interface Formatter { |
|
init(services: Services, i18nextOptions: InitOptions): void; |
|
add(name: string, fc: (value: any, lng: string | undefined, options: any) => string): void; |
|
addCached( |
|
name: string, |
|
fc: (lng: string | undefined, options: any) => (value: any) => string, |
|
): void; |
|
format: FormatFunction; |
|
} |
|
|
|
export interface Services { |
|
backendConnector: any; |
|
i18nFormat: any; |
|
interpolator: Interpolator; |
|
languageDetector: any; |
|
languageUtils: any; |
|
logger: any; |
|
pluralResolver: any; |
|
resourceStore: ResourceStore; |
|
formatter?: Formatter; |
|
} |
|
|
|
export type ModuleType = |
|
| 'backend' |
|
| 'logger' |
|
| 'languageDetector' |
|
| 'postProcessor' |
|
| 'i18nFormat' |
|
| 'formatter' |
|
| '3rdParty'; |
|
|
|
export interface Module { |
|
type: ModuleType; |
|
} |
|
|
|
export type CallbackError = Error | string | null | undefined; |
|
export type ReadCallback = ( |
|
err: CallbackError, |
|
data: ResourceKey | boolean | null | undefined, |
|
) => void; |
|
export type MultiReadCallback = (err: CallbackError, data: Resource | null | undefined) => void; |
|
|
|
|
|
|
|
|
|
|
|
|
|
export interface BackendModule<Options = object> extends Module { |
|
type: 'backend'; |
|
init(services: Services, backendOptions: Options, i18nextOptions: InitOptions): void; |
|
read(language: string, namespace: string, callback: ReadCallback): void; |
|
|
|
create?( |
|
languages: readonly string[], |
|
namespace: string, |
|
key: string, |
|
fallbackValue: string, |
|
): void; |
|
|
|
readMulti?( |
|
languages: readonly string[], |
|
namespaces: readonly string[], |
|
callback: MultiReadCallback, |
|
): void; |
|
|
|
save?(language: string, namespace: string, data: ResourceLanguage): void; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
export interface LanguageDetectorModule extends Module { |
|
type: 'languageDetector'; |
|
init?(services: Services, detectorOptions: object, i18nextOptions: InitOptions): void; |
|
|
|
detect(): string | readonly string[] | undefined; |
|
cacheUserLanguage?(lng: string): void; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
export interface LanguageDetectorAsyncModule extends Module { |
|
type: 'languageDetector'; |
|
|
|
async: true; |
|
init?(services: Services, detectorOptions: object, i18nextOptions: InitOptions): void; |
|
|
|
detect( |
|
callback: (lng: string | readonly string[] | undefined) => void | undefined, |
|
): void | Promise<string | readonly string[] | undefined>; |
|
cacheUserLanguage?(lng: string): void | Promise<void>; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
export interface PostProcessorModule extends Module { |
|
|
|
name: string; |
|
type: 'postProcessor'; |
|
process(value: string, key: string | string[], options: TOptions, translator: any): string; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
export interface LoggerModule extends Module { |
|
type: 'logger'; |
|
log(...args: any[]): void; |
|
warn(...args: any[]): void; |
|
error(...args: any[]): void; |
|
} |
|
|
|
export interface I18nFormatModule extends Module { |
|
type: 'i18nFormat'; |
|
} |
|
|
|
export interface FormatterModule extends Module, Formatter { |
|
type: 'formatter'; |
|
} |
|
|
|
export interface ThirdPartyModule extends Module { |
|
type: '3rdParty'; |
|
init(i18next: i18n): void; |
|
} |
|
|
|
export interface Modules { |
|
backend?: BackendModule; |
|
logger?: LoggerModule; |
|
languageDetector?: LanguageDetectorModule | LanguageDetectorAsyncModule; |
|
i18nFormat?: I18nFormatModule; |
|
formatter?: FormatterModule; |
|
external: ThirdPartyModule[]; |
|
} |
|
|
|
|
|
export interface Newable<T> { |
|
new (...args: any[]): T; |
|
} |
|
export interface NewableModule<T extends Module> extends Newable<T> { |
|
type: T['type']; |
|
} |
|
|
|
export type Callback = (error: any, t: TFunction) => void; |
|
|
|
|
|
|
|
|
|
export interface ExistsFunction< |
|
TKeys extends string = string, |
|
TInterpolationMap extends object = $Dictionary, |
|
> { |
|
(key: TKeys | TKeys[], options?: TOptions<TInterpolationMap>): boolean; |
|
} |
|
|
|
export interface CloneOptions extends InitOptions { |
|
|
|
|
|
|
|
|
|
|
|
forkResourceStore?: boolean; |
|
} |
|
|
|
export interface CustomInstanceExtensions {} |
|
|
|
|
|
|
|
|
|
type InferArrayValuesElseReturnType<T> = T extends (infer A)[] ? A : T; |
|
|
|
|
|
export interface i18n extends CustomInstanceExtensions { |
|
|
|
t: TFunction< |
|
[ |
|
...$NormalizeIntoArray<DefaultNamespace>, |
|
...Exclude<FlatNamespace, InferArrayValuesElseReturnType<DefaultNamespace>>[], |
|
] |
|
>; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
init(callback?: Callback): Promise<TFunction>; |
|
init<T>(options: InitOptions<T>, callback?: Callback): Promise<TFunction>; |
|
|
|
loadResources(callback?: (err: any) => void): void; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
use<T extends Module>(module: T | NewableModule<T> | Newable<T>): this; |
|
|
|
|
|
|
|
|
|
modules: Modules; |
|
|
|
|
|
|
|
|
|
services: Services; |
|
|
|
|
|
|
|
|
|
store: ResourceStore; |
|
|
|
|
|
|
|
|
|
exists: ExistsFunction; |
|
|
|
|
|
|
|
|
|
getDataByLanguage(lng: string): { [key: string]: { [key: string]: string } } | undefined; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
getFixedT< |
|
Ns extends Namespace | null = DefaultNamespace, |
|
TKPrefix extends KeyPrefix<ActualNs> = undefined, |
|
ActualNs extends Namespace = Ns extends null ? DefaultNamespace : Ns, |
|
>( |
|
...args: |
|
| [lng: string | readonly string[], ns?: Ns, keyPrefix?: TKPrefix] |
|
| [lng: null, ns: Ns, keyPrefix?: TKPrefix] |
|
): TFunction<ActualNs, TKPrefix>; |
|
|
|
|
|
|
|
|
|
|
|
changeLanguage(lng?: string, callback?: Callback): Promise<TFunction>; |
|
|
|
|
|
|
|
|
|
|
|
language: string; |
|
|
|
|
|
|
|
|
|
languages: readonly string[]; |
|
|
|
|
|
|
|
|
|
|
|
resolvedLanguage?: string; |
|
|
|
|
|
|
|
|
|
|
|
hasLoadedNamespace( |
|
ns: string | readonly string[], |
|
options?: { |
|
lng?: string | readonly string[]; |
|
precheck: ( |
|
i18n: i18n, |
|
loadNotPending: ( |
|
lng: string | readonly string[], |
|
ns: string | readonly string[], |
|
) => boolean, |
|
) => boolean; |
|
}, |
|
): boolean; |
|
|
|
|
|
|
|
|
|
loadNamespaces(ns: string | readonly string[], callback?: Callback): Promise<void>; |
|
|
|
|
|
|
|
|
|
loadLanguages(lngs: string | readonly string[], callback?: Callback): Promise<void>; |
|
|
|
|
|
|
|
|
|
reloadResources( |
|
lngs?: string | readonly string[], |
|
ns?: string | readonly string[], |
|
callback?: () => void, |
|
): Promise<void>; |
|
reloadResources(lngs: null, ns: string | readonly string[], callback?: () => void): Promise<void>; |
|
|
|
|
|
|
|
|
|
setDefaultNamespace(ns: string): void; |
|
|
|
|
|
|
|
|
|
hasLoadedNamespace(ns: string, options?: Pick<InitOptions, 'fallbackLng'>): boolean; |
|
|
|
|
|
|
|
|
|
dir(lng?: string): 'ltr' | 'rtl'; |
|
|
|
|
|
|
|
|
|
format: FormatFunction; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
createInstance(options?: InitOptions, callback?: Callback): i18n; |
|
|
|
|
|
|
|
|
|
|
|
cloneInstance(options?: CloneOptions, callback?: Callback): i18n; |
|
|
|
|
|
|
|
|
|
on(event: 'initialized', callback: (options: InitOptions) => void): void; |
|
|
|
|
|
|
|
|
|
on( |
|
event: 'loaded', |
|
callback: (loaded: { [language: string]: { [namespace: string]: boolean } }) => void, |
|
): void; |
|
|
|
|
|
|
|
|
|
on(event: 'failedLoading', callback: (lng: string, ns: string, msg: string) => void): void; |
|
|
|
|
|
|
|
|
|
on( |
|
event: 'missingKey', |
|
callback: (lngs: readonly string[], namespace: string, key: string, res: string) => void, |
|
): void; |
|
|
|
|
|
|
|
|
|
on(event: 'added' | 'removed', callback: (lng: string, ns: string) => void): void; |
|
|
|
|
|
|
|
|
|
on(event: 'languageChanged', callback: (lng: string) => void): void; |
|
|
|
|
|
|
|
|
|
on(event: string, listener: (...args: any[]) => void): void; |
|
|
|
|
|
|
|
|
|
|
|
off(event: string, listener?: (...args: any[]) => void): void; |
|
|
|
|
|
|
|
|
|
getResource( |
|
lng: string, |
|
ns: string, |
|
key: string, |
|
options?: Pick<InitOptions, 'keySeparator' | 'ignoreJSONStructure'>, |
|
): any; |
|
|
|
|
|
|
|
|
|
addResource( |
|
lng: string, |
|
ns: string, |
|
key: string, |
|
value: string, |
|
options?: { keySeparator?: string; silent?: boolean }, |
|
): i18n; |
|
|
|
|
|
|
|
|
|
addResources(lng: string, ns: string, resources: any): i18n; |
|
|
|
|
|
|
|
|
|
|
|
|
|
addResourceBundle( |
|
lng: string, |
|
ns: string, |
|
resources: any, |
|
deep?: boolean, |
|
overwrite?: boolean, |
|
): i18n; |
|
|
|
|
|
|
|
|
|
hasResourceBundle(lng: string, ns: string): boolean; |
|
|
|
|
|
|
|
|
|
getResourceBundle(lng: string, ns: string): any; |
|
|
|
|
|
|
|
|
|
removeResourceBundle(lng: string, ns: string): i18n; |
|
|
|
|
|
|
|
|
|
options: InitOptions; |
|
|
|
|
|
|
|
|
|
isInitialized: boolean; |
|
|
|
|
|
|
|
|
|
isInitializing: boolean; |
|
|
|
|
|
|
|
|
|
initializedStoreOnce: boolean; |
|
|
|
|
|
|
|
|
|
initializedLanguageOnce: boolean; |
|
|
|
|
|
|
|
|
|
emit(eventName: string, ...args: any[]): void; |
|
} |
|
|
|
export type * from './typescript/options.js'; |
|
export type { |
|
|
|
FallbackLngObjList, |
|
FallbackLng, |
|
InitOptions, |
|
TypeOptions, |
|
CustomTypeOptions, |
|
CustomPluginOptions, |
|
PluginOptions, |
|
FormatFunction, |
|
InterpolationOptions, |
|
ReactOptions, |
|
ResourceKey, |
|
ResourceLanguage, |
|
Resource, |
|
TOptions, |
|
Namespace, |
|
DefaultNamespace, |
|
FlatNamespace, |
|
} from './typescript/options.js'; |
|
export type * from './typescript/t.js'; |
|
export type { |
|
TFunction, |
|
ParseKeys, |
|
TFunctionReturn, |
|
TFunctionDetailedResult, |
|
KeyPrefix, |
|
} from './typescript/t.js'; |
|
|
|
declare const i18next: i18n; |
|
export default i18next; |
|
|
|
export const createInstance: i18n['createInstance']; |
|
|
|
export const dir: i18n['dir']; |
|
export const init: i18n['init']; |
|
export const loadResources: i18n['loadResources']; |
|
export const reloadResources: i18n['reloadResources']; |
|
export const use: i18n['use']; |
|
export const changeLanguage: i18n['changeLanguage']; |
|
export const getFixedT: i18n['getFixedT']; |
|
export const t: i18n['t']; |
|
export const exists: i18n['exists']; |
|
export const setDefaultNamespace: i18n['setDefaultNamespace']; |
|
export const hasLoadedNamespace: i18n['hasLoadedNamespace']; |
|
export const loadNamespaces: i18n['loadNamespaces']; |
|
export const loadLanguages: i18n['loadLanguages']; |
|
|