Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,21 @@
"main": "./lib/index.js",
"module": "./es/index.js",
"jsnext:main": "./es/index.js",
"typings": "lib/index.d.ts",
"files": [
"*.md",
"es",
"lib",
"dist"
],
"scripts": {
"build": "npm run build:commonjs && npm run build:es && npm run build:flow && npm run build:umd && npm run build:umd:min",
"build": "npm run build:commonjs && npm run build:es && npm run build:flow && npm run build:umd && npm run build:umd:min && npm run copy:ts",
"build:commonjs": "rimraf lib && cross-env BABEL_ENV=commonjs babel ./src -d lib",
"build:es": "rimraf es && cross-env BABEL_ENV=es babel ./src -d es",
"build:umd": "rimraf dist && webpack --env.dev --output-filename dist/ReactLocalizeRedux.js",
"build:umd:min": "webpack --env.prod --output-filename dist/ReactLocalizeRedux.min.js",
"build:flow": "flow-copy-source ./src lib && flow-copy-source ./src es",
"copy:ts": "ncp ./src/index.d.ts ./lib/index.d.ts && ncp ./src/index.d.ts ./es/index.d.ts",
"coverage": "jest --coverage",
"prepublish": "npm run build",
"start": "webpack-dev-server --config examples/webpack.config.babel.js --content-base examples --inline --open",
Expand Down Expand Up @@ -79,6 +81,7 @@
"html-webpack-plugin": "^2.24.1",
"jest": "^20.0.4",
"json-loader": "^0.5.4",
"ncp": "^2.0.0",
"progress-bar-webpack-plugin": "^1.9.1",
"react": "^15.6.1",
"react-addons-test-utils": "^15.6.0",
Expand Down
122 changes: 122 additions & 0 deletions src/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
import { ReactElement } from 'react';
import { Selector } from 'reselect';
import { ComponentClass } from 'react-redux';

export as namespace ReactLocalizeRedux;

export interface Language {
code: string;
active: boolean;
}

export interface Translations {
[key: string]: string[];
}

export interface Options {
renderInnerHtml?: boolean;
defaultLanguage?: string;
}

export interface LocaleState {
languages: Language[];
translations: Translations;
options: Options;
}

export interface TranslatedLanguage {
[key: string]: string;
}

export type LocalizedElement = ReactElement<'span'>|string;

export interface LocalizedElementMap {
[key: string]: LocalizedElement;
}

export interface TranslatePlaceholderData {
[key: string]: string|number;
}

export type TranslateValue = string|string[];

interface BaseAction<T, P> {
type: T;
payload: P;
}

export type Translate = (value: TranslateValue, data: TranslatePlaceholderData, options?: Options) => LocalizedElement|LocalizedElementMap;

type InitializePayload = {
languageCodes: string[],
options?: Options
};

type AddTranslationPayload = {
translation: Object
};

type AddTranslationForLanguagePayload = {
translation: Object,
language: string
};

type SetLanguagesPayload = {
languageCodes: string[],
activeLanguage?: string
};

type SetActiveLanguagePayload = {
languageCode: string
};

type LocalizeProps = {
currentLanguage: string,
translate: Translate
};

export type InitializeAction = BaseAction<'@@localize/INITIALIZE', InitializePayload>;
export type AddTranslationAction = BaseAction<'@@localize/ADD_TRANSLATION', AddTranslationPayload>;
export type AddTranslationForLanguageAction = BaseAction<'@@localize/ADD_TRANSLATION_FOR_LANGUGE', AddTranslationForLanguagePayload>;
export type SetActiveLanguageAction = BaseAction<'@@localize/SET_ACTIVE_LANGUAGE', SetActiveLanguagePayload>;
export type SetLanguagesAction = BaseAction<'@@localize/SET_LANGUAGES', SetLanguagesPayload>;

export type Action = BaseAction<
string,
& InitializePayload
& AddTranslationPayload
& AddTranslationForLanguagePayload
& SetActiveLanguagePayload
& SetLanguagesPayload
>;

export type ActionLanguageCodes = Action & { languageCodes: string[] };

export interface LocalizeStateProps {
currentLanguage: string;
translate: Translate;
}

export function localeReducer(state: LocaleState, action: Action): LocaleState;

export function initialize(languageCodes: string[], options: Options): InitializeAction;

export function addTranslation(translation: Object): AddTranslationAction;

export function addTranslationForLanguage(translation: Object, language: string): AddTranslationForLanguageAction;

export function setLanguages(languageCodes: string[], activeLanguage: string): SetLanguagesAction;

export function setActiveLanguage(languageCode: string): SetActiveLanguageAction;

export function getTranslations(state: LocaleState): Translations;

export function getLanguages(state: LocaleState): Language[];

export function getOptions(state: LocaleState): Options;

export function getActiveLanguage(state: LocaleState): Language;

export function getTranslate(state: LocaleState): Selector<LocaleState, Translate>;

export function localize(Component: ReactElement<any>, slice?: string): (state: LocaleState) => ComponentClass<LocalizeProps>;
2 changes: 1 addition & 1 deletion src/modules/locale.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ export const localeReducer = (state: LocaleState = initialState, action: Action)
/**
* ACTION CREATORS
*/
export const initialize = (languageCodes: string[], options: Options = defaultTranslateOptions) => ({
export const initialize = (languageCodes: string[], options: Options = defaultTranslateOptions): InitializeAction => ({
type: INITIALIZE,
payload: { languageCodes, options }
});
Expand Down