mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-06-28 22:30:01 +00:00
Merge pull request #29945 from beheh/react-i18next
[react-i18next] Remove typings as they were upstreamed
This commit is contained in:
@@ -1206,6 +1206,12 @@
|
||||
"sourceRepoURL": "https://github.com/react-ga/react-ga",
|
||||
"asOfVersion": "2.3.0"
|
||||
},
|
||||
{
|
||||
"libraryName": "react-i18next",
|
||||
"typingsPackageName": "react-i18next",
|
||||
"sourceRepoURL": "https://github.com/i18next/react-i18next",
|
||||
"asOfVersion": "8.1.0"
|
||||
},
|
||||
{
|
||||
"libraryName": "react-monaco-editor",
|
||||
"typingsPackageName": "react-monaco-editor",
|
||||
|
||||
45
types/react-i18next/index.d.ts
vendored
45
types/react-i18next/index.d.ts
vendored
@@ -1,45 +0,0 @@
|
||||
// Type definitions for react-i18next 7.8
|
||||
// Project: https://github.com/i18next/react-i18next
|
||||
// Definitions by: Giedrius Grabauskas <https://github.com/GiedriusGrabauskas>
|
||||
// Simon Baumann <https://github.com/chnoch>
|
||||
// Benedict Etzel <https://github.com/beheh>
|
||||
// Wu Haotian <https://github.com/whtsky>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.8
|
||||
|
||||
import { TranslationFunction } from "i18next";
|
||||
|
||||
import {
|
||||
setDefaults,
|
||||
getDefaults,
|
||||
setI18n,
|
||||
getI18n,
|
||||
ReactI18NextOptions,
|
||||
reactI18nextModule
|
||||
} from "./src/context";
|
||||
import I18n from "./src/I18n";
|
||||
import I18nextProvider from "./src/I18nextProvider";
|
||||
import Interpolate from "./src/interpolate";
|
||||
import loadNamespaces from "./src/loadNamespaces";
|
||||
import Trans from "./src/trans";
|
||||
import translate from "./src/translate";
|
||||
|
||||
export {
|
||||
setDefaults,
|
||||
getDefaults,
|
||||
setI18n,
|
||||
getI18n,
|
||||
ReactI18NextOptions,
|
||||
reactI18nextModule,
|
||||
I18n,
|
||||
I18nextProvider,
|
||||
Interpolate,
|
||||
loadNamespaces,
|
||||
Trans,
|
||||
translate,
|
||||
TranslationFunction
|
||||
};
|
||||
|
||||
export { InjectedI18nProps, InjectedTranslateProps } from "./src/props";
|
||||
|
||||
export as namespace reactI18Next;
|
||||
21
types/react-i18next/src/I18n.d.ts
vendored
21
types/react-i18next/src/I18n.d.ts
vendored
@@ -1,21 +0,0 @@
|
||||
import * as React from "react";
|
||||
import { i18n, TranslationFunction } from "i18next";
|
||||
|
||||
export interface Options {
|
||||
i18n: i18n;
|
||||
t: TranslationFunction;
|
||||
}
|
||||
|
||||
export interface i18nProps {
|
||||
wait?: boolean;
|
||||
ns?: string | string[];
|
||||
nsMode?: string;
|
||||
bindI18n?: string;
|
||||
bindStore?: string;
|
||||
i18n?: i18n;
|
||||
initialI18nStore?: any;
|
||||
initialLanguage?: string;
|
||||
children: (t: TranslationFunction, options: Options) => React.ReactNode;
|
||||
}
|
||||
|
||||
export default class I18n extends React.Component<i18nProps> { }
|
||||
12
types/react-i18next/src/I18nextProvider.d.ts
vendored
12
types/react-i18next/src/I18nextProvider.d.ts
vendored
@@ -1,12 +0,0 @@
|
||||
import * as React from "react";
|
||||
import { i18n } from "i18next";
|
||||
|
||||
// tslint:disable-next-line:interface-name
|
||||
export interface I18nextProviderProps {
|
||||
i18n: i18n;
|
||||
initialI18nStore?: any;
|
||||
initialLanguage?: string;
|
||||
children: React.ReactNode;
|
||||
}
|
||||
|
||||
export default class I18nextProvider extends React.Component<I18nextProviderProps> { }
|
||||
26
types/react-i18next/src/context.d.ts
vendored
26
types/react-i18next/src/context.d.ts
vendored
@@ -1,26 +0,0 @@
|
||||
import { i18n } from "i18next";
|
||||
|
||||
export interface ReactI18NextOptions {
|
||||
wait?: boolean;
|
||||
withRef?: boolean;
|
||||
bindI18n?: string;
|
||||
bindStore?: string;
|
||||
translateFuncName?: string;
|
||||
nsMode?: string;
|
||||
}
|
||||
|
||||
export function setDefaults(options: ReactI18NextOptions): void;
|
||||
|
||||
export function getDefaults(): ReactI18NextOptions;
|
||||
|
||||
export function setI18n(instance: i18n): void;
|
||||
|
||||
export function getI18n(): i18n;
|
||||
|
||||
export interface i18NextModule {
|
||||
type: string;
|
||||
|
||||
init: (instance: i18n) => void;
|
||||
}
|
||||
|
||||
export const reactI18nextModule: i18NextModule;
|
||||
25
types/react-i18next/src/interpolate.d.ts
vendored
25
types/react-i18next/src/interpolate.d.ts
vendored
@@ -1,25 +0,0 @@
|
||||
import * as React from "react";
|
||||
import { i18n, InterpolationOptions, TranslationFunction } from "i18next";
|
||||
|
||||
export type InterpolateValue = string | JSX.Element;
|
||||
|
||||
export interface InterpolatePropsBase {
|
||||
parent?: string;
|
||||
regexp?: RegExp;
|
||||
useDangerouslySetInnerHTML?: boolean;
|
||||
dangerouslySetInnerHTMLPartElement?: string;
|
||||
options?: InterpolationOptions;
|
||||
i18nKey?: string;
|
||||
className?: string;
|
||||
style?: React.CSSProperties;
|
||||
i18n?: i18n;
|
||||
t?: TranslationFunction;
|
||||
}
|
||||
|
||||
export interface OtherInterpolateProps {
|
||||
[regexKey: string]: InterpolateValue | RegExp | InterpolationOptions | boolean | undefined;
|
||||
}
|
||||
|
||||
export type InterpolateProps = InterpolatePropsBase & OtherInterpolateProps;
|
||||
|
||||
export default class Interpolate extends React.PureComponent<InterpolateProps> { }
|
||||
9
types/react-i18next/src/loadNamespaces.d.ts
vendored
9
types/react-i18next/src/loadNamespaces.d.ts
vendored
@@ -1,9 +0,0 @@
|
||||
import * as React from "react";
|
||||
import { i18n } from "i18next";
|
||||
|
||||
export interface LoadNamespacesArguments {
|
||||
components: Array<React.ComponentClass<any> | React.StatelessComponent<any>>;
|
||||
i18n: i18n;
|
||||
}
|
||||
|
||||
export default function loadNamespaces(args: LoadNamespacesArguments): Promise<void>;
|
||||
24
types/react-i18next/src/props.d.ts
vendored
24
types/react-i18next/src/props.d.ts
vendored
@@ -1,24 +0,0 @@
|
||||
import { i18n as I18n, TranslationFunction } from "i18next";
|
||||
|
||||
/**
|
||||
* Extend your component's Prop interface with this one to get access to `this.props.t`
|
||||
*
|
||||
* Please note that if you use the `translateFuncName` option, you should create
|
||||
* your own interface just like this one, but with your name of the translation function.
|
||||
*
|
||||
* interface MyComponentProps extends ReactI18next.InjectedTranslateProps {}
|
||||
*
|
||||
* Then specify the name of the translate function as generic argument
|
||||
*
|
||||
* const translated = translate<string, "_">("view", { translateFuncName: "_" })(YourComponent);
|
||||
*/
|
||||
export interface InjectedTranslateProps {
|
||||
t: TranslationFunction;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extend your component's Prop interface with this one to get access to `this.props.i18n`
|
||||
*/
|
||||
export interface InjectedI18nProps {
|
||||
i18n: I18n;
|
||||
}
|
||||
25
types/react-i18next/src/trans.d.ts
vendored
25
types/react-i18next/src/trans.d.ts
vendored
@@ -1,25 +0,0 @@
|
||||
import * as React from "react";
|
||||
import { i18n, TranslationFunction } from "i18next";
|
||||
|
||||
export interface TOptions {
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
export interface Values {
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
export interface TransProps {
|
||||
i18nKey?: string;
|
||||
count?: number;
|
||||
parent?: React.ReactNode | (() => React.ReactNode);
|
||||
i18n?: i18n;
|
||||
t?: TranslationFunction;
|
||||
tOptions?: TOptions;
|
||||
defaults?: string;
|
||||
values?: Values;
|
||||
components?: React.ReactNode[];
|
||||
ns?: string;
|
||||
}
|
||||
|
||||
export default class Trans extends React.Component<TransProps> { }
|
||||
63
types/react-i18next/src/translate.d.ts
vendored
63
types/react-i18next/src/translate.d.ts
vendored
@@ -1,63 +0,0 @@
|
||||
import * as React from "react";
|
||||
import { i18n as I18n, TranslationFunction } from "i18next";
|
||||
import { InjectedTranslateProps, InjectedI18nProps } from "./props";
|
||||
import { setDefaults, setI18n } from "./context";
|
||||
|
||||
export interface TranslateOptions<TTranslateFuncName extends string = string> {
|
||||
withRef?: boolean;
|
||||
bindI18n?: string;
|
||||
bindStore?: string;
|
||||
translateFuncName?: TTranslateFuncName;
|
||||
wait?: boolean;
|
||||
nsMode?: string;
|
||||
i18n?: I18n;
|
||||
}
|
||||
|
||||
export interface TranslateHocProps {
|
||||
i18n?: I18n;
|
||||
initialI18nStore?: object;
|
||||
initialLanguage?: string;
|
||||
}
|
||||
|
||||
// Diff / Omit taken from https://github.com/Microsoft/TypeScript/issues/12215#issuecomment-311923766
|
||||
type Omit<T, K extends keyof T> = Pick<T, ({ [P in keyof T]: P } & { [P in K]: never } & { [x: string]: never, [x: number]: never })[keyof T]>;
|
||||
|
||||
type InjectedProps = InjectedI18nProps & InjectedTranslateProps;
|
||||
|
||||
export interface WrapperComponentClass<P = {}, PWrapped = {}> extends React.ComponentClass<P & TranslateHocProps> {
|
||||
new (props: P, context?: any): React.Component<P & TranslateHocProps, React.ComponentState> & { getWrappedInstance(): React.Component<PWrapped> };
|
||||
}
|
||||
|
||||
// Injects props and removes them from the prop requirements.
|
||||
// Adds the new properties t (or whatever the translation function is called) and i18n if needed.
|
||||
export type InferableComponentEnhancerWithProps<TTranslateFunctionName extends string> =
|
||||
<P extends { [key: string]: any }>(component: React.ComponentClass<P> | React.StatelessComponent<P>) =>
|
||||
React.ComponentClass<Omit<P, keyof InjectedI18nProps | TTranslateFunctionName> & TranslateHocProps>;
|
||||
|
||||
export type InferableComponentEnhancerWithPropsAndRef<TTranslateFunctionName extends string> =
|
||||
<P extends { [key: string]: any }>(component: React.ComponentClass<P> | React.StatelessComponent<P>) =>
|
||||
WrapperComponentClass<Omit<P, keyof InjectedI18nProps | TTranslateFunctionName>, P>;
|
||||
|
||||
export interface Translate {
|
||||
<TNamespace extends string>
|
||||
(namespaces?: TNamespace | TNamespace[], options?: Omit<TranslateOptions, "translateFuncName"> & { withRef?: false }):
|
||||
InferableComponentEnhancerWithProps<"t">;
|
||||
|
||||
<TNamespace extends string>
|
||||
(namespaces?: TNamespace | TNamespace[], options?: Omit<TranslateOptions, "translateFuncName"> & { withRef: true }):
|
||||
InferableComponentEnhancerWithPropsAndRef<"t">;
|
||||
|
||||
<TNamespace extends string, TTranslateFunctionName extends string>
|
||||
(namespaces?: TNamespace | TNamespace[], options?: TranslateOptions<TTranslateFunctionName> & { withRef?: false }):
|
||||
InferableComponentEnhancerWithProps<TTranslateFunctionName>;
|
||||
|
||||
<TNamespace extends string, TTranslateFunctionName extends string>
|
||||
(namespaces?: TNamespace | TNamespace[], options?: TranslateOptions<TTranslateFunctionName> & { withRef: true }):
|
||||
InferableComponentEnhancerWithPropsAndRef<TTranslateFunctionName>;
|
||||
|
||||
setDefaults: typeof setDefaults;
|
||||
setI18n: typeof setI18n;
|
||||
}
|
||||
|
||||
declare const translate: Translate;
|
||||
export default translate;
|
||||
@@ -1,201 +0,0 @@
|
||||
import * as React from 'react';
|
||||
import * as i18n from 'i18next';
|
||||
import {
|
||||
setDefaults,
|
||||
reactI18nextModule,
|
||||
translate,
|
||||
I18nextProvider,
|
||||
Interpolate,
|
||||
InjectedTranslateProps,
|
||||
TranslationFunction,
|
||||
loadNamespaces,
|
||||
Trans,
|
||||
I18n,
|
||||
ReactI18NextOptions
|
||||
} from 'react-i18next';
|
||||
import { InjectedI18nProps } from 'react-i18next/src/props';
|
||||
|
||||
interface InnerAnotherComponentProps {
|
||||
_: TranslationFunction;
|
||||
}
|
||||
|
||||
class InnerAnotherComponent extends React.Component<InnerAnotherComponentProps> {
|
||||
render() {
|
||||
const _ = this.props._;
|
||||
return <p>{_('content.text', {/* options t options */})}</p>;
|
||||
}
|
||||
}
|
||||
|
||||
const AnotherComponent = translate<Key, "_">('view', {wait: true, translateFuncName: '_'})(InnerAnotherComponent);
|
||||
const instanceWithoutRef = new AnotherComponent({});
|
||||
instanceWithoutRef.componentWillReceiveProps!({
|
||||
i18n,
|
||||
initialI18nStore: { context: { text: "a message" } },
|
||||
initialLanguage: "en"
|
||||
}, {});
|
||||
|
||||
translate.setDefaults({ wait: false });
|
||||
translate.setI18n(i18n);
|
||||
|
||||
const AnotherComponentWithRef = translate<Key, "_">("view" as Key, { translateFuncName: "_", withRef: true })(InnerAnotherComponent);
|
||||
const instanceWithRef = new AnotherComponentWithRef({});
|
||||
const ref = instanceWithRef.getWrappedInstance();
|
||||
instanceWithRef.componentWillReceiveProps!({
|
||||
i18n,
|
||||
initialI18nStore: { context: { text: "a message" } },
|
||||
initialLanguage: "en"
|
||||
}, {});
|
||||
|
||||
class InnerYetAnotherComponent extends React.Component<InjectedTranslateProps> {
|
||||
render() {
|
||||
const t = this.props.t;
|
||||
return <p>{t('usingDefaultNS', {/* options t options */})}</p>;
|
||||
}
|
||||
}
|
||||
|
||||
const YetAnotherComponent = translate()(InnerYetAnotherComponent);
|
||||
|
||||
const YetAnotherComponentWithRef = translate(undefined, { withRef: true })(InnerYetAnotherComponent);
|
||||
new YetAnotherComponentWithRef({}).getWrappedInstance();
|
||||
class TranslatableView extends React.Component<InjectedTranslateProps> {
|
||||
render() {
|
||||
const t = this.props.t;
|
||||
const interpolateComponent = <strong>"a interpolated component"</strong>;
|
||||
const options: i18n.InterpolationOptions = {};
|
||||
return (
|
||||
<div>
|
||||
<h1>{t('common:appName')}</h1>
|
||||
<AnotherComponent/>
|
||||
<YetAnotherComponent/>
|
||||
<Interpolate
|
||||
parent='p'
|
||||
i18nKey='common:interpolateSample'
|
||||
value='"some value in props"'
|
||||
component={interpolateComponent}
|
||||
/>
|
||||
<Interpolate
|
||||
parent='p'
|
||||
options={options}
|
||||
i18nKey='common:interpolateSample'
|
||||
useDangerouslySetInnerHTML={true}
|
||||
dangerouslySetInnerHTMLPartElement='span'
|
||||
value='"some value in props"'
|
||||
component={interpolateComponent}
|
||||
i18n={i18n.init()}
|
||||
/>
|
||||
<a href='https://github.com/i18next/react-i18next' target='_blank'>{t('nav:link1')}</a>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
const TranslatedView = translate(["view", "nav"] as Key[], { wait: true })(TranslatableView);
|
||||
|
||||
class App extends React.Component {
|
||||
render() {
|
||||
return (
|
||||
<div className='main'>
|
||||
<main>
|
||||
<TranslatedView />
|
||||
</main>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
<I18nextProvider i18n={i18n} initialLanguage={'en'} initialI18nStore={{}}>
|
||||
<App/>
|
||||
</I18nextProvider>;
|
||||
|
||||
<I18nextProvider i18n={i18n} initialLanguage={'en'} initialI18nStore={{}}>
|
||||
123
|
||||
</I18nextProvider>;
|
||||
|
||||
loadNamespaces({components: [App], i18n}).then(() => {
|
||||
}).catch(error => {
|
||||
});
|
||||
|
||||
<Trans count={5}/>;
|
||||
<Trans count={5} i18nKey="key"/>;
|
||||
<Trans parent={'span'}/>;
|
||||
<Trans parent={<div />}/>;
|
||||
<Trans parent={() => <div />}/>;
|
||||
<Trans i18n={i18n.init()}/>;
|
||||
<Trans t={i18n.getFixedT('en')}/>;
|
||||
<Trans count={5}>
|
||||
<App/>
|
||||
</Trans>;
|
||||
<Trans i18nKey="hello" tOptions={{hello: "world", count: 42}}/>;
|
||||
<Trans
|
||||
defaults="Hello <0>{{universe}}</0>!"
|
||||
components={[
|
||||
<strong>placeholder</strong>
|
||||
]}
|
||||
values={{
|
||||
universe: "World"
|
||||
}}
|
||||
/>;
|
||||
|
||||
type Key = "view" | "nav";
|
||||
|
||||
class GenericsTest extends React.Component<InjectedTranslateProps> {
|
||||
render() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
const TranslatedGenericsTest = translate(["view", "nav"] as Key[])(GenericsTest);
|
||||
<TranslatedGenericsTest />;
|
||||
|
||||
class GenericsTest2 extends React.Component<InjectedTranslateProps> {
|
||||
render() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
const TranslatedGenericsTest2 = translate("view" as Key)(GenericsTest2);
|
||||
<TranslatedGenericsTest2 />;
|
||||
|
||||
class ComponentWithInjectedI18n extends React.Component<InjectedI18nProps> {
|
||||
render() { return null; }
|
||||
}
|
||||
|
||||
const TranslatedComponentWithInjectedI18n = translate()(ComponentWithInjectedI18n);
|
||||
<TranslatedComponentWithInjectedI18n />;
|
||||
|
||||
function StatlessComponent(props: InjectedTranslateProps) {
|
||||
return <h1>{props.t("hy")}</h1>;
|
||||
}
|
||||
|
||||
const TranslatedStatlessComponent = translate()(StatlessComponent);
|
||||
<TranslatedStatlessComponent />;
|
||||
|
||||
interface CustomTranslateFunctionProps {
|
||||
_: TranslationFunction;
|
||||
}
|
||||
|
||||
<I18n ns={['defaultNamespace', 'anotherNamespace']} wait={true} nsMode={'string'} bindI18n={'languageChanged loaded'}
|
||||
bindStore={'added removed'}>
|
||||
{
|
||||
(t, {i18n}) => (
|
||||
<div>
|
||||
<h1>{t('keyFromDefault')}</h1>
|
||||
<p>{t('anotherNamespace:key.from.another.namespace', {/* options t options */})}</p>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
</I18n>;
|
||||
|
||||
<I18n>
|
||||
{t => '123'}
|
||||
</I18n>;
|
||||
|
||||
const defaults: ReactI18NextOptions = {
|
||||
wait: true,
|
||||
withRef: true,
|
||||
bindI18n: 'string',
|
||||
bindStore: 'string'
|
||||
};
|
||||
setDefaults(defaults);
|
||||
|
||||
reactI18nextModule.init(i18n.init());
|
||||
@@ -1,33 +0,0 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6",
|
||||
"dom"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"jsx": "react",
|
||||
"experimentalDecorators": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"test/react-i18next-tests.tsx",
|
||||
"src/context.d.ts",
|
||||
"src/I18n.d.ts",
|
||||
"src/I18nextProvider.d.ts",
|
||||
"src/interpolate.d.ts",
|
||||
"src/loadNamespaces.d.ts",
|
||||
"src/trans.d.ts",
|
||||
"src/translate.d.ts"
|
||||
]
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
57
types/react-i18next/v1/index.d.ts
vendored
57
types/react-i18next/v1/index.d.ts
vendored
@@ -1,57 +0,0 @@
|
||||
// Type definitions for react-i18next 1.7.0
|
||||
// Project: https://github.com/i18next/react-i18next
|
||||
// Definitions by: Kostya Esmukov <https://github.com/KostyaEsmukov>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.8
|
||||
|
||||
import * as I18next from "i18next";
|
||||
import * as React from "react";
|
||||
|
||||
export type TranslationFunction = I18next.TranslationFunction;
|
||||
|
||||
// Extend your component's Prop interface with this one to get access to `this.props.t`
|
||||
//
|
||||
// Please note that if you use the `translateFuncName` option, you should create
|
||||
// your own interface just like this one, but with your name of the translation function.
|
||||
//
|
||||
// interface MyComponentProps extends ReactI18next.InjectedTranslateProps {}
|
||||
export interface InjectedTranslateProps {
|
||||
t?: TranslationFunction;
|
||||
}
|
||||
|
||||
interface I18nextProviderProps {
|
||||
i18n: I18next.I18n;
|
||||
children?: React.ReactElement<any>;
|
||||
}
|
||||
|
||||
export class I18nextProvider extends React.Component<I18nextProviderProps> { }
|
||||
|
||||
|
||||
type InterpolateValue = string | JSX.Element;
|
||||
|
||||
interface InterpolateProps {
|
||||
i18nKey: string;
|
||||
|
||||
parent?: string;
|
||||
regexp?: RegExp;
|
||||
options?: I18next.TranslationOptions;
|
||||
|
||||
useDangerouslySetInnerHTML?: boolean;
|
||||
dangerouslySetInnerHTMLPartElement?: string;
|
||||
|
||||
[regexKey: string]: InterpolateValue | RegExp | I18next.TranslationOptions | boolean | undefined;
|
||||
}
|
||||
|
||||
export class Interpolate extends React.Component<InterpolateProps> { }
|
||||
|
||||
interface TranslateOptions {
|
||||
withRef?: boolean;
|
||||
wait?: boolean;
|
||||
translateFuncName?: string;
|
||||
}
|
||||
|
||||
export function translate(namespaces?: string[] | string, options?: TranslateOptions): <C extends Function>(WrappedComponent: C) => C;
|
||||
|
||||
export function loadNamespaces({ components, i18n }: { components: (React.ComponentClass<any> | React.StatelessComponent<any>)[], i18n: I18next.I18n }): Promise<void>;
|
||||
|
||||
export as namespace ReactI18Next;
|
||||
@@ -1,103 +0,0 @@
|
||||
import * as ReactDOM from 'react-dom';
|
||||
import * as React from 'react';
|
||||
import * as i18n from 'i18next';
|
||||
import { translate, I18nextProvider, Interpolate, InjectedTranslateProps, TranslationFunction } from 'react-i18next';
|
||||
|
||||
|
||||
i18n
|
||||
.init({
|
||||
fallbackLng: 'en',
|
||||
|
||||
// have a common namespace used around the full app
|
||||
ns: ['common'],
|
||||
defaultNS: 'common',
|
||||
|
||||
debug: true,
|
||||
|
||||
interpolation: {
|
||||
escapeValue: false // not needed for react!!
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
interface InnerAnotherComponentProps {
|
||||
_?: TranslationFunction;
|
||||
}
|
||||
|
||||
class InnerAnotherComponent extends React.Component<InnerAnotherComponentProps> {
|
||||
render() {
|
||||
const _ = this.props._!;
|
||||
|
||||
return <p>{_('content.text', { /* options t options */ })}</p>;
|
||||
}
|
||||
}
|
||||
|
||||
const AnotherComponent = translate('view', { wait: true, translateFuncName: '_' })(InnerAnotherComponent);
|
||||
|
||||
|
||||
|
||||
interface InnerYetAnotherComponentProps extends InjectedTranslateProps {
|
||||
}
|
||||
|
||||
class InnerYetAnotherComponent extends React.Component<InnerYetAnotherComponentProps> {
|
||||
render() {
|
||||
const t = this.props.t!;
|
||||
|
||||
return <p>{t('usingDefaultNS', { /* options t options */ })}</p>;
|
||||
}
|
||||
}
|
||||
const YetAnotherComponent = translate()(InnerYetAnotherComponent);
|
||||
|
||||
|
||||
interface TranslatableViewProps extends InjectedTranslateProps {
|
||||
}
|
||||
|
||||
@translate(['view', 'nav'], { wait: true })
|
||||
class TranslatableView extends React.Component<TranslatableViewProps> {
|
||||
render() {
|
||||
const t = this.props.t!;
|
||||
|
||||
let interpolateComponent = <strong>"a interpolated component"</strong>;
|
||||
|
||||
return (
|
||||
<div>
|
||||
<h1>{t('common:appName')}</h1>
|
||||
<AnotherComponent />
|
||||
<YetAnotherComponent />
|
||||
<Interpolate
|
||||
parent='p'
|
||||
i18nKey='common:interpolateSample'
|
||||
value='"some value in props"'
|
||||
component={interpolateComponent}
|
||||
/>
|
||||
<Interpolate
|
||||
parent='p'
|
||||
i18nKey='common:interpolateSample'
|
||||
useDangerouslySetInnerHTML={true}
|
||||
dangerouslySetInnerHTMLPartElement='span'
|
||||
value='"some value in props"'
|
||||
component={interpolateComponent}
|
||||
/>
|
||||
<a href='https://github.com/i18next/react-i18next' target='_blank'>{t('nav:link1')}</a>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
class App extends React.Component {
|
||||
render() {
|
||||
return (
|
||||
<div className='main'>
|
||||
<main>
|
||||
<TranslatableView />
|
||||
</main>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ReactDOM.render(
|
||||
<I18nextProvider i18n={ i18n }><App /></I18nextProvider>,
|
||||
document.getElementById('app')
|
||||
);
|
||||
@@ -1,34 +0,0 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6",
|
||||
"dom"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../../",
|
||||
"typeRoots": [
|
||||
"../../"
|
||||
],
|
||||
"paths": {
|
||||
"react-i18next": [
|
||||
"react-i18next/v1"
|
||||
],
|
||||
"i18next": [
|
||||
"i18next/v2"
|
||||
]
|
||||
},
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"jsx": "react",
|
||||
"experimentalDecorators": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"react-i18next-tests.tsx"
|
||||
]
|
||||
}
|
||||
@@ -1,79 +0,0 @@
|
||||
{
|
||||
"extends": "dtslint/dt.json",
|
||||
"rules": {
|
||||
"adjacent-overload-signatures": false,
|
||||
"array-type": false,
|
||||
"arrow-return-shorthand": false,
|
||||
"ban-types": false,
|
||||
"callable-types": false,
|
||||
"comment-format": false,
|
||||
"dt-header": false,
|
||||
"eofline": false,
|
||||
"export-just-namespace": false,
|
||||
"import-spacing": false,
|
||||
"interface-name": false,
|
||||
"interface-over-type-literal": false,
|
||||
"jsdoc-format": false,
|
||||
"max-line-length": false,
|
||||
"member-access": false,
|
||||
"new-parens": false,
|
||||
"no-any-union": false,
|
||||
"no-boolean-literal-compare": false,
|
||||
"no-conditional-assignment": false,
|
||||
"no-consecutive-blank-lines": false,
|
||||
"no-construct": false,
|
||||
"no-declare-current-package": false,
|
||||
"no-duplicate-imports": false,
|
||||
"no-duplicate-variable": false,
|
||||
"no-empty-interface": false,
|
||||
"no-for-in-array": false,
|
||||
"no-inferrable-types": false,
|
||||
"no-internal-module": false,
|
||||
"no-irregular-whitespace": false,
|
||||
"no-mergeable-namespace": false,
|
||||
"no-misused-new": false,
|
||||
"no-namespace": false,
|
||||
"no-object-literal-type-assertion": false,
|
||||
"no-padding": false,
|
||||
"no-redundant-jsdoc": false,
|
||||
"no-redundant-jsdoc-2": false,
|
||||
"no-redundant-undefined": false,
|
||||
"no-reference-import": false,
|
||||
"no-relative-import-in-test": false,
|
||||
"no-self-import": false,
|
||||
"no-single-declare-module": false,
|
||||
"no-string-throw": false,
|
||||
"no-unnecessary-callback-wrapper": false,
|
||||
"no-unnecessary-class": false,
|
||||
"no-unnecessary-generics": false,
|
||||
"no-unnecessary-qualifier": false,
|
||||
"no-unnecessary-type-assertion": false,
|
||||
"no-useless-files": false,
|
||||
"no-var-keyword": false,
|
||||
"no-var-requires": false,
|
||||
"no-void-expression": false,
|
||||
"no-trailing-whitespace": false,
|
||||
"object-literal-key-quotes": false,
|
||||
"object-literal-shorthand": false,
|
||||
"one-line": false,
|
||||
"one-variable-per-declaration": false,
|
||||
"only-arrow-functions": false,
|
||||
"prefer-conditional-expression": false,
|
||||
"prefer-const": false,
|
||||
"prefer-declare-function": false,
|
||||
"prefer-for-of": false,
|
||||
"prefer-method-signature": false,
|
||||
"prefer-template": false,
|
||||
"radix": false,
|
||||
"semicolon": false,
|
||||
"space-before-function-paren": false,
|
||||
"space-within-parens": false,
|
||||
"strict-export-declare-modifiers": false,
|
||||
"trim-file": false,
|
||||
"triple-equals": false,
|
||||
"typedef-whitespace": false,
|
||||
"unified-signatures": false,
|
||||
"void-return": false,
|
||||
"whitespace": false
|
||||
}
|
||||
}
|
||||
12
types/react-i18next/v4/I18nextProvider.d.ts
vendored
12
types/react-i18next/v4/I18nextProvider.d.ts
vendored
@@ -1,12 +0,0 @@
|
||||
import * as React from "react";
|
||||
import { i18n } from "i18next";
|
||||
|
||||
// tslint:disable-next-line:interface-name
|
||||
export interface I18nextProviderProps {
|
||||
i18n: i18n;
|
||||
children: React.ReactElement<any>;
|
||||
initialI18nStore?: any;
|
||||
initialLanguage?: string;
|
||||
}
|
||||
|
||||
export default class I18nextProvider extends React.Component<I18nextProviderProps> { }
|
||||
38
types/react-i18next/v4/index.d.ts
vendored
38
types/react-i18next/v4/index.d.ts
vendored
@@ -1,38 +0,0 @@
|
||||
// Type definitions for react-i18next 4.6
|
||||
// Project: https://github.com/i18next/react-i18next
|
||||
// Definitions by: Giedrius Grabauskas <https://github.com/GiedriusGrabauskas>
|
||||
// Netanel Gilad <https://github.com/netanelgilad>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.8
|
||||
|
||||
import { TranslationFunction } from "i18next";
|
||||
|
||||
import I18nextProvider from "./I18nextProvider";
|
||||
import Interpolate from "./interpolate";
|
||||
import loadNamespaces from "./loadNamespaces";
|
||||
import Trans from "./trans";
|
||||
import translate from "./translate";
|
||||
|
||||
export {
|
||||
I18nextProvider,
|
||||
Interpolate,
|
||||
loadNamespaces,
|
||||
Trans,
|
||||
translate,
|
||||
// Exports for TypeScript only
|
||||
TranslationFunction
|
||||
};
|
||||
|
||||
/**
|
||||
* Extend your component's Prop interface with this one to get access to `this.props.t`
|
||||
*
|
||||
* Please note that if you use the `translateFuncName` option, you should create
|
||||
* your own interface just like this one, but with your name of the translation function.
|
||||
*
|
||||
* interface MyComponentProps extends ReactI18next.InjectedTranslateProps {}
|
||||
*/
|
||||
export interface InjectedTranslateProps {
|
||||
t: TranslationFunction;
|
||||
}
|
||||
|
||||
export as namespace reactI18Next;
|
||||
23
types/react-i18next/v4/interpolate.d.ts
vendored
23
types/react-i18next/v4/interpolate.d.ts
vendored
@@ -1,23 +0,0 @@
|
||||
import * as React from "react";
|
||||
import { InterpolationOptions } from "i18next";
|
||||
|
||||
export type InterpolateValue = string | JSX.Element;
|
||||
|
||||
export interface InterpolatePropsBase {
|
||||
parent?: string;
|
||||
regexp?: RegExp;
|
||||
useDangerouslySetInnerHTML?: boolean;
|
||||
dangerouslySetInnerHTMLPartElement?: string;
|
||||
options?: InterpolationOptions;
|
||||
i18nKey?: string;
|
||||
className?: string;
|
||||
style?: React.CSSProperties;
|
||||
}
|
||||
|
||||
export interface OtherInterpolateProps {
|
||||
[regexKey: string]: InterpolateValue | RegExp | InterpolationOptions | boolean | undefined;
|
||||
}
|
||||
|
||||
export type InterpolateProps = InterpolatePropsBase & OtherInterpolateProps;
|
||||
|
||||
export default class Interpolate extends React.Component<InterpolateProps> { }
|
||||
9
types/react-i18next/v4/loadNamespaces.d.ts
vendored
9
types/react-i18next/v4/loadNamespaces.d.ts
vendored
@@ -1,9 +0,0 @@
|
||||
import * as React from "react";
|
||||
import { i18n } from "i18next";
|
||||
|
||||
export interface LoadNamespacesArguments {
|
||||
components: Array<React.ComponentClass<any> | React.StatelessComponent<any>>;
|
||||
i18n: i18n;
|
||||
}
|
||||
|
||||
export default function loadNamespaces(args: LoadNamespacesArguments): Promise<void>;
|
||||
@@ -1,95 +0,0 @@
|
||||
import * as React from 'react';
|
||||
import * as i18n from 'i18next';
|
||||
import { translate, I18nextProvider, Interpolate, InjectedTranslateProps, TranslationFunction, loadNamespaces, Trans } from 'react-i18next';
|
||||
|
||||
interface InnerAnotherComponentProps {
|
||||
_?: TranslationFunction;
|
||||
}
|
||||
|
||||
class InnerAnotherComponent extends React.Component<InnerAnotherComponentProps> {
|
||||
render() {
|
||||
const _ = this.props._!;
|
||||
return <p>{_('content.text', { /* options t options */ })}</p>;
|
||||
}
|
||||
}
|
||||
|
||||
const AnotherComponent = translate('view', { wait: true, translateFuncName: '_' })(InnerAnotherComponent);
|
||||
|
||||
class InnerYetAnotherComponent extends React.Component<InjectedTranslateProps> {
|
||||
render() {
|
||||
const t = this.props.t;
|
||||
return <p>{t('usingDefaultNS', { /* options t options */ })}</p>;
|
||||
}
|
||||
}
|
||||
|
||||
const YetAnotherComponent = translate()(InnerYetAnotherComponent);
|
||||
|
||||
class TranslatableView extends React.Component<InjectedTranslateProps> {
|
||||
render() {
|
||||
const t = this.props.t;
|
||||
const interpolateComponent = <strong>"a interpolated component"</strong>;
|
||||
|
||||
return (
|
||||
<div>
|
||||
<h1>{t('common:appName')}</h1>
|
||||
<AnotherComponent />
|
||||
<YetAnotherComponent />
|
||||
<Interpolate
|
||||
parent='p'
|
||||
i18nKey='common:interpolateSample'
|
||||
value='"some value in props"'
|
||||
component={interpolateComponent}
|
||||
/>
|
||||
<Interpolate
|
||||
parent='p'
|
||||
i18nKey='common:interpolateSample'
|
||||
useDangerouslySetInnerHTML={true}
|
||||
dangerouslySetInnerHTMLPartElement='span'
|
||||
value='"some value in props"'
|
||||
component={interpolateComponent}
|
||||
/>
|
||||
<a href='https://github.com/i18next/react-i18next' target='_blank'>{t('nav:link1')}</a>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
const WrappedTranslatableView = translate(['view', 'nav'], { wait: true })(TranslatableView);
|
||||
|
||||
class App extends React.Component {
|
||||
render() {
|
||||
return (
|
||||
<div className='main'>
|
||||
<main>
|
||||
<WrappedTranslatableView />
|
||||
</main>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
<I18nextProvider i18n={i18n}>
|
||||
<App />
|
||||
</I18nextProvider>;
|
||||
|
||||
loadNamespaces({ components: [App], i18n }).then(() => { }).catch(error => { });
|
||||
|
||||
<Trans count={5} />;
|
||||
<Trans count={5} i18nKey="key" />;
|
||||
<Trans count={5}>
|
||||
<App />
|
||||
</Trans>;
|
||||
|
||||
type Key = "view" | "nav";
|
||||
|
||||
class GenericsTest extends React.Component<InjectedTranslateProps> {
|
||||
render() { return null; }
|
||||
}
|
||||
|
||||
translate<Key>(['view', 'nav'])(GenericsTest);
|
||||
|
||||
class GenericsTest2 extends React.Component<InjectedTranslateProps> {
|
||||
render() { return null; }
|
||||
}
|
||||
|
||||
translate<Key>('view')(GenericsTest2);
|
||||
8
types/react-i18next/v4/trans.d.ts
vendored
8
types/react-i18next/v4/trans.d.ts
vendored
@@ -1,8 +0,0 @@
|
||||
import * as React from "react";
|
||||
|
||||
export interface TransProps {
|
||||
i18nKey?: string;
|
||||
[name: string]: any;
|
||||
}
|
||||
|
||||
export default class Trans extends React.Component<TransProps> { }
|
||||
25
types/react-i18next/v4/translate.d.ts
vendored
25
types/react-i18next/v4/translate.d.ts
vendored
@@ -1,25 +0,0 @@
|
||||
import * as React from "react";
|
||||
import { i18n } from "i18next";
|
||||
import { InjectedTranslateProps } from "react-i18next";
|
||||
|
||||
export interface TranslateOptions {
|
||||
withRef?: boolean;
|
||||
bindI18n?: string;
|
||||
bindStore?: string;
|
||||
translateFuncName?: string;
|
||||
wait?: boolean;
|
||||
nsMode?: string;
|
||||
i18n?: i18n;
|
||||
}
|
||||
|
||||
// Diff / Omit taken from https://github.com/Microsoft/TypeScript/issues/12215#issuecomment-311923766
|
||||
export type Omit<T, K extends keyof T> = Pick<T, ({ [P in keyof T]: P } & { [P in K]: never } & { [x: string]: never, [x: number]: never })[keyof T]>;
|
||||
|
||||
// Injects props and removes them from the prop requirements.
|
||||
// Adds the new properties t (or whatever the translation function is called) and i18n if needed.
|
||||
export type InferableComponentEnhancerWithProps<TTranslateFunctionName extends string> =
|
||||
<P extends { [key: string]: any }>(component: React.ComponentClass<P> | React.StatelessComponent<P>) =>
|
||||
React.ComponentClass<Omit<P, keyof InjectedTranslateProps | TTranslateFunctionName>>;
|
||||
|
||||
// tslint:disable-next-line:ban-types
|
||||
export default function translate<TKey extends string = string>(namespaces?: TKey[] | TKey, options?: TranslateOptions): InferableComponentEnhancerWithProps<"t">;
|
||||
@@ -1,36 +0,0 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6",
|
||||
"dom"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../../",
|
||||
"typeRoots": [
|
||||
"../../"
|
||||
],
|
||||
"paths": {
|
||||
"react-i18next": [
|
||||
"react-i18next/v4"
|
||||
]
|
||||
},
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"jsx": "react",
|
||||
"experimentalDecorators": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"react-i18next-tests.tsx",
|
||||
"I18nextProvider.d.ts",
|
||||
"interpolate.d.ts",
|
||||
"loadNamespaces.d.ts",
|
||||
"trans.d.ts",
|
||||
"translate.d.ts"
|
||||
]
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user