Ste*_*ann 7 internationalization reactjs react-native
我使用的是i18n模块(https://github.com/AlexanderZaytsev/react-native-i18n).它工作得很好,但我想将翻译分成单独的文件.我来自一篇很好的博客文章(https://blog.redradix.com/6-essential-libraries-to-use-on-your-next-react-native-app/),它显示了我想做的用例.
// 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>
)
}
Run Code Online (Sandbox Code Playgroud)
我收到一个错误:"无法读取未定义的属性't'.一般来说,我是新手.我错了什么?
我的问题中的代码就像一个魅力.我在导入的顶部只有错误的括号
改变自:
import { I18n } from '../config/i18n'
Run Code Online (Sandbox Code Playgroud)
至:
import I18n from '../config/i18n'
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1967 次 |
| 最近记录: |