1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | import {Locale} from 'locale';
|
10 |
|
11 | import {FetchToken} from 'fusion-tokens';
|
12 | import type {Context} from 'fusion-core';
|
13 | import {UniversalEventsToken} from 'fusion-plugin-universal-events';
|
14 |
|
15 | import {HydrationStateToken} from './browser';
|
16 | import {I18nLoaderToken} from './tokens.js';
|
17 |
|
18 | export type TranslationsObjectType = {[string]: string};
|
19 |
|
20 | type ExtractReturnType = <V>(() => V) => V;
|
21 |
|
22 | export type TranslateFuncType = (
|
23 | key: string,
|
24 | interpolations?: {+[string]: string | number}
|
25 | ) => string;
|
26 |
|
27 | export type I18nDepsType = {
|
28 | fetch?: typeof FetchToken.optional,
|
29 | hydrationState?: typeof HydrationStateToken.optional,
|
30 | loader?: typeof I18nLoaderToken.optional,
|
31 | events?: typeof UniversalEventsToken.optional,
|
32 | };
|
33 |
|
34 | export type IEmitter = $Call<ExtractReturnType, typeof UniversalEventsToken>;
|
35 |
|
36 | export type I18nServiceType = {
|
37 | from: (
|
38 | ctx: Context
|
39 | ) => {
|
40 | +locale?: string | Locale,
|
41 | +translations?: TranslationsObjectType,
|
42 | +load: (Array<string>) => Promise<void>,
|
43 | +translate: TranslateFuncType,
|
44 | },
|
45 | };
|