UNPKG

1.22 kBJavaScriptView Raw
1/** Copyright (c) 2018 Uber Technologies, Inc.
2 *
3 * This source code is licensed under the MIT license found in the
4 * LICENSE file in the root directory of this source tree.
5 *
6 * @flow
7 */
8
9import {Locale} from 'locale';
10
11import {FetchToken} from 'fusion-tokens';
12import type {Context} from 'fusion-core';
13import {UniversalEventsToken} from 'fusion-plugin-universal-events';
14
15import {HydrationStateToken} from './browser';
16import {I18nLoaderToken} from './tokens.js';
17
18export type TranslationsObjectType = {[string]: string};
19
20type ExtractReturnType = <V>(() => V) => V;
21
22export type TranslateFuncType = (
23 key: string,
24 interpolations?: {+[string]: string | number}
25) => string;
26
27export type I18nDepsType = {
28 fetch?: typeof FetchToken.optional,
29 hydrationState?: typeof HydrationStateToken.optional,
30 loader?: typeof I18nLoaderToken.optional,
31 events?: typeof UniversalEventsToken.optional,
32};
33
34export type IEmitter = $Call<ExtractReturnType, typeof UniversalEventsToken>;
35
36export 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};