Would this work with React Native + Expo? #352
-
Hi! I have a project with react native + expo multiplatform (Web, Android, IOS) that I need to internationalize with TS. Is there a way to compile for Android and IOS? |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 8 replies
-
To be honest: I don't know. |
Beta Was this translation helpful? Give feedback.
-
I tried to use it with react-native and it works, but (!) I am configure |
Beta Was this translation helpful? Give feedback.
-
Interestingly, Expo recommends typesafe-i18n in this guide: https://docs.expo.dev/guides/localization/#complete-example (see where it says "Using other translation libraries"). It mentions that you need to be using Hermes as your javascript engine (easy to configure in expo), and I suppose the implicit requirement is that you're on the latest version of Expo (SDK 47 at time of writing). However, that wasn't enough to get typesafe-i18n working. There were 2 issues: CJS filesAs @whalemare points out, before metro version 0.72.0, you need to add 'cjs' to your
The linked issue claims that this is resolved in metro version 0.72.0. Expo SDK 47 uses react-native 0.70.5, which uses metro 0.70.3. So, you still need to do this workaround. Intl implementationEven with Expo SDK 47 with Hermes' support for the Intl API on iOS and Android, it doesn't appear that it supports all of the Intl API. You can see that various constructors are still not supported: https://hermesengine.dev/docs/intl/#not-yet-supported. I found that I needed to use polyfill to add these in. My code was: package.json
App.tsx or App.js
Note that I've enabled dynamic imports in my tsconfig.json with the compilerOption: ConclusionI think Expo have assumed that since Hermes "supports" Intl that typescript-i18n will work just fine. But that doesn't appear to be the case. @whalemare, I'd be interested to see how you got it working, and if you needed to do this polyfill step or if something else worked for you. |
Beta Was this translation helpful? Give feedback.
-
@ivanhofer found a time to make PR: #531 It's totally looks like #522 from @chriscoomber (thank you), but for bare react-native and contains only required set of changes with minimal reproducible example |
Beta Was this translation helpful? Give feedback.
-
for anyone who is struggling to find way to implement the |
Beta Was this translation helpful? Give feedback.
Interestingly, Expo recommends typesafe-i18n in this guide: https://docs.expo.dev/guides/localization/#complete-example (see where it says "Using other translation libraries"). It mentions that you need to be using Hermes as your javascript engine (easy to configure in expo), and I suppose the implicit requirement is that you're on the latest version of Expo (SDK 47 at time of writing).
However, that wasn't enough to get typesafe-i18n working. There were 2 issues:
CJS files
As @whalemare points out, before metro version 0.72.0, you need to add 'cjs' to your
metro.config.js
under sourceExts. Something like: