I am using the i18n module ( https://github.com/AlexanderZaytsev/react-native-i18n ). It works fine, but I want to split translations into separate files. I came across a nice blog post ( https://blog.redradix.com/6-essential-libraries-to-use-on-your-next-react-native-app/ ) which shows how we want how to do it.
// src/config/locales/en.js const en = { welcome: 'welcome', }; export default en; // src/config/locales/es.js const es = { welcome: 'bienvenido', }; export default es; //src/config/i18n.js import I18n from 'react-native-i18n'; import es from './locales/es'; import en from './locales/en'; I18n.fallbacks = true; I18n.translations = { en: en, es: es, }; export default I18n; //usage in components import I18n from '../config/i18n'; render() { return ( <Text>{I18n.t('welcome')}</Text> ) }
An error occurred: "Unable to read property" t "undefined". I am new to the reaction in general. What did I misunderstand?
reactjs internationalization react-native
Stephan hofmann
source share