react-native 中使用i18n
yarn add react-native-i18n
配置 index.js
import i18n from "react-native-i18n";
import en from "./en";
import zh from "./zh";
i18n.defaultLocale = "en";
i18n.fallbacks = true;
i18n.translations = {
en,
zh,
};
export { i18n };
配置 en.js
export default {
home: {
title: "first app",
},
};
配置 zh.js
export default {
home: {
title: "第一个app",
},
};
使用
import { i18n } from "../i18n"
render() {
return (
<Text>
i18n.t('home.title')
</Text>
)
}