diff --git a/react-i18next/react-i18next-tests.tsx b/react-i18next/react-i18next-tests.tsx new file mode 100644 index 0000000000..d9faea8ac2 --- /dev/null +++ b/react-i18next/react-i18next-tests.tsx @@ -0,0 +1,95 @@ +/// +/// +/// +/// + + +import * as ReactDOM from 'react-dom'; +import * as React from 'react'; +import * as i18n from 'i18next'; +import { translate, I18nextProvider, Interpolate, InjectedTranslateProps } 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 extends InjectedTranslateProps { +} + +class InnerAnotherComponent extends React.Component { + render() { + const { t } = this.props; + + return

{t('content.text', { /* options t options */ })}

; + } +} + +const AnotherComponent = translate('view', { wait: true })(InnerAnotherComponent); + + + +interface InnerYetAnotherComponentProps extends InjectedTranslateProps { +} + +class InnerYetAnotherComponent extends React.Component { + render() { + const { t } = this.props; + + return

{t('usingDefaultNS', { /* options t options */ })}

; + } +} +const YetAnotherComponent = translate()(InnerYetAnotherComponent); + + +interface TranslatableViewProps extends InjectedTranslateProps { +} + +@translate(['view', 'nav'], { wait: true }) +class TranslatableView extends React.Component { + render() { + const { t } = this.props; + + let interpolateComponent = "a interpolated component"; + + return ( +
+

{t('common:appName')}

+ + + + {t('nav:link1')} +
+ ) + } +} + +class App extends React.Component<{}, {}> { + render() { + return ( +
+
+ +
+
+ ); + } +} + + +ReactDOM.render( + , + document.getElementById('app') +); diff --git a/react-i18next/react-i18next.d.ts b/react-i18next/react-i18next.d.ts new file mode 100644 index 0000000000..0720e6e4ed --- /dev/null +++ b/react-i18next/react-i18next.d.ts @@ -0,0 +1,56 @@ +// Type definitions for react-i18next 1.6.3 +// Project: https://github.com/i18next/react-i18next +// Definitions by: Kostya Esmukov +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// +/// +/// + + +declare namespace ReactI18next { + import React = __React; + + // Extend your component's Prop interface with this one to get access to `this.props.t` + // + // interface MyComponentProps extends ReactI18next.InjectedTranslateProps {} + export interface InjectedTranslateProps { + t?: I18next.TranslationFunction; + } + + interface I18nextProviderProps { + i18n: I18next.I18n; + children?: React.ReactElement; + } + + export class I18nextProvider extends React.Component { } + + + type InterpolateValue = string | JSX.Element; + + interface InterpolateProps { + i18nKey: string; + + parent?: string; + regexp?: RegExp; + options?: I18next.TranslationOptions; + + [regexKey: string]: InterpolateValue | RegExp | I18next.TranslationOptions; + } + + export class Interpolate extends React.Component { } + + interface TranslateOptions { + withRef?: boolean; + wait?: boolean; + } + + export function translate(namespaces?: string[] | string, options?: TranslateOptions): (WrappedComponent: C) => C; + + export function loadNamespaces({ components, i18n }: { components: ReactRouter.RouteComponent[], i18n: I18next.I18n }): Promise; + +} + +declare module 'react-i18next' { + export = ReactI18next; +}