(0, _reactI18next.translate) is not a function

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-11 07:47:08

问题


Actually I am new to react native and here I am trying to change language to Arabic using 'react-i18next' but when executed the following error ocures

ReactNativeJS ▶︎ (0, _reactI18next.translate) is not a function. (In '(0, _reactI18next.translate)('common', { bindI18n: 'languageChanged', bindStore: false })', '(0, _reactI18next.translate)' is undefined)

this is my code

import React from 'react';
import AppNavigator from './src/controller/AppNavigator';
import { translate } from 'react-i18next';
// import i18n from './src/I18n/index';
console.reportErrorsAsExceptions = false;

const WrappedStack = ({ t }) => {
  return <AppNavigator screenProps={{ t }} />;
};
const ReloadAppOnLanguageChange = translate('common', {
  bindI18n: 'languageChanged',
  bindStore: false,
})(WrappedStack);

export default class App extends React.Component {
  render() {
    return (
      <ReloadAppOnLanguageChange/>
    );
  }
}

AppNavigator.js

import {
    createStackNavigator,
    createAppContainer,
} from 'react-navigation';
import SScreen from '../view/sScreen/SScreen';
import Login from '../view/login/Login';
import SignUp from '../view/signUp/SignUp';
import TabNavigation from '../controller/TabNavigation';
import ForgotPassword from '../view/forgotPassword/ForgotPassword';
import AddAppointment from '../view/addAppointment/AddAppointment';
import DrProfile from '../view/drProfile/DrProfile';
import PaymentHistory from '../view/paymentHistory/PaymentHistory';


const AppNavigator = createStackNavigator({
    SScreen: {
        screen: SScreen,
        navigationOptions: {
            header: null
        }
    },
    Login: {
        screen: Login,
        navigationOptions: {
            header: null
        }
    },
    SignUp: {
        screen: SignUp,
        navigationOptions: {
            header: null
        }
    },
    ForgotPassword: {
        screen: ForgotPassword,
        navigationOptions: {
            header: null
        }
    },
    TabNavigation: {
        screen: TabNavigation,
        navigationOptions: {
            header: null,
            title: "TabNavigation",
            headerStyle: {
                backgroundColor: '#B78FC3',
            },
            headerTintColor: 'white',
            headerTitleStyle: {
                fontWeight: 'bold',
            },
            headerTitleStyle: {
                flex: 1,
                textAlign: 'center',
            },
            headerLeft: null
        },
    },
    AddAppointment: {
        screen: AddAppointment,
        navigationOptions: {
            title: "Add An Appointment",
            headerStyle: {
                backgroundColor: '#B78FC3',
            },
            headerTintColor: 'white',
            headerTitleStyle: {
                fontWeight: 'bold',
            },
            headerTitleStyle: {
                flex: 1,
                textAlign: 'center',
            },
        },
    },
    DrProfile: {
        screen: DrProfile,
        navigationOptions: {
            headerStyle: {
                backgroundColor: '#B78FC3',
            },
            headerTintColor: 'white',
            headerTitleStyle: {
                fontWeight: 'bold',
            },
            headerTitleStyle: {
                flex: 1,
                textAlign: 'center',
            },
        },
    },
    PaymentHistory: {
        screen: PaymentHistory,
        navigationOptions: {
            title: "Payment History",
            headerStyle: {
                backgroundColor: '#B78FC3',
            },
            headerTintColor: 'white',
            headerTitleStyle: {
                fontWeight: 'bold',
            },
            headerTitleStyle: {
                flex: 1,
                textAlign: 'center',
            },
        },
    },
},
    { headerLayoutPreset: 'center' });


const App = createAppContainer(AppNavigator);
export default App; 

回答1:


Use withTranslation() instead of translate() HOC. Seems like this one is missing in the migration docs.



来源:https://stackoverflow.com/questions/57591779/0-reacti18next-translate-is-not-a-function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!