1+ import { ReactElement } from 'react' ;
2+ import { Selector } from 'reselect' ;
3+ import { ComponentClass } from 'react-redux' ;
4+
5+ export as namespace ReactLocalizeRedux ;
6+
7+ export interface Language {
8+ code : string ;
9+ active : boolean ;
10+ }
11+
12+ export interface Translations {
13+ [ key : string ] : string [ ] ;
14+ }
15+
16+ export interface Options {
17+ renderInnerHtml ?: boolean ;
18+ defaultLanguage ?: string ;
19+ }
20+
21+ export interface LocaleState {
22+ languages : Language [ ] ;
23+ translations : Translations ;
24+ options : Options ;
25+ }
26+
27+ export interface TranslatedLanguage {
28+ [ key : string ] : string ;
29+ }
30+
31+ export type LocalizedElement = ReactElement < 'span' > | string ;
32+
33+ export interface LocalizedElementMap {
34+ [ key : string ] : LocalizedElement ;
35+ }
36+
37+ export interface TranslatePlaceholderData {
38+ [ key : string ] : string | number ;
39+ }
40+
41+ export type TranslateValue = string | string [ ] ;
42+
43+ interface BaseAction < T , P > {
44+ type : T ;
45+ payload : P ;
46+ }
47+
48+ export type Translate = ( value : TranslateValue , data : TranslatePlaceholderData , options ?: Options ) => LocalizedElement | LocalizedElementMap ;
49+
50+ type InitializePayload = {
51+ languageCodes : string [ ] ,
52+ options ?: Options
53+ } ;
54+
55+ type AddTranslationPayload = {
56+ translation : Object
57+ } ;
58+
59+ type AddTranslationForLanguagePayload = {
60+ translation : Object ,
61+ language : string
62+ } ;
63+
64+ type SetLanguagesPayload = {
65+ languageCodes : string [ ] ,
66+ activeLanguage ?: string
67+ } ;
68+
69+ type SetActiveLanguagePayload = {
70+ languageCode : string
71+ } ;
72+
73+ type LocalizeProps = {
74+ currentLanguage : string ,
75+ translate : Translate
76+ } ;
77+
78+ export type InitializeAction = BaseAction < '@@localize/INITIALIZE' , InitializePayload > ;
79+ export type AddTranslationAction = BaseAction < '@@localize/ADD_TRANSLATION' , AddTranslationPayload > ;
80+ export type AddTranslationForLanguageAction = BaseAction < '@@localize/ADD_TRANSLATION_FOR_LANGUGE' , AddTranslationForLanguagePayload > ;
81+ export type SetActiveLanguageAction = BaseAction < '@@localize/SET_ACTIVE_LANGUAGE' , SetActiveLanguagePayload > ;
82+ export type SetLanguagesAction = BaseAction < '@@localize/SET_LANGUAGES' , SetLanguagesPayload > ;
83+
84+ export type Action = BaseAction <
85+ string ,
86+ & InitializePayload
87+ & AddTranslationPayload
88+ & AddTranslationForLanguagePayload
89+ & SetActiveLanguagePayload
90+ & SetLanguagesPayload
91+ > ;
92+
93+ export type ActionLanguageCodes = Action & { languageCodes : string [ ] } ;
94+
95+ export interface LocalizeStateProps {
96+ currentLanguage : string ;
97+ translate : Translate ;
98+ }
99+
100+ export function localeReducer ( state : LocaleState , action : Action ) : LocaleState ;
101+
102+ export function initialize ( languageCodes : string [ ] , options : Options ) : InitializeAction ;
103+
104+ export function addTranslation ( translation : Object ) : AddTranslationAction ;
105+
106+ export function addTranslationForLanguage ( translation : Object , language : string ) : AddTranslationForLanguageAction ;
107+
108+ export function setLanguages ( languageCodes : string [ ] , activeLanguage : string ) : SetLanguagesAction ;
109+
110+ export function setActiveLanguage ( languageCode : string ) : SetActiveLanguageAction ;
111+
112+ export function getTranslations ( state : LocaleState ) : Translations ;
113+
114+ export function getLanguages ( state : LocaleState ) : Language [ ] ;
115+
116+ export function getOptions ( state : LocaleState ) : Options ;
117+
118+ export function getActiveLanguage ( state : LocaleState ) : Language ;
119+
120+ export function getTranslate ( state : LocaleState ) : Selector < LocaleState , Translate > ;
121+
122+ export function localize ( Component : ReactElement < any > , slice ?: string ) : ( state : LocaleState ) => ComponentClass < LocalizeProps > ;
0 commit comments