alibaba / react-intl-universal

Internationalize React apps. Not only for Component but also for Vanilla JS.
1.33k stars 153 forks source link

请问在taro中怎么使用 #250

Open xian107 opened 4 months ago

xian107 commented 4 months ago

image image 加了localeDone会报错,去掉localeDone国际化又不起作用,强制重渲染APP组件都没用

cwtuan commented 4 months ago

show more code

xian107 commented 4 months ago

show more code @cwtuan image image 把{localeDone ? children : null}改成 {children} 不会报错了,但是国家化失效了,需要relaunch访问到其他页面再切回来才有效。 `import { Provider } from "react-redux"; import intl from "react-intl-universal"; import Taro from "@tarojs/taro"; import { useEffect, useState } from "react"; import { store } from "./store";

function App({ children }: any): any { const [localeDone, setLocaleDone] = useState(false); useEffect(() => { Taro.request({ url: "get url api", // 异步获取json文件 success(res: any = {}) { if (res.statusCode === 200 && res.url) { Taro.request({ url: res.url, success(result: any = {}) { console.log("返回json", result.data); if (result.statusCode === 200 && result.data) { intl .init({ currentLocale: "en-US", locales: { "en-US": result.data.EN, "zh-CN": result.data.CH, }, }) .then(() => { setLocaleDone(true); }); } }, }); } }, }); }, []); return {localeDone ? children : null}; } export default App;`