Open rdewolff opened 3 years ago
Additional info on StackOverflow : https://stackoverflow.com/questions/49637158/react-native-release-crash-because-of-unkown-module-momentjs-locale
react-native-calendar-strip
relies on Moment's localization features. You will need to follow Moment's requirements.
Here's a boilerplate setup: https://github.com/BugiDev/react-native-calendar-strip#localization
The answer to the SO you linked also mentions calling Moment's locale()
method e.g. moment().locale('fr');
. Your app would need to call that whenever the user changes languages. The locale
prop passed to RNCS will also need to change to match.
Here's what I have in my app.js pertaining to localization:
import moment from "moment"; import "moment/locale/ja"; import "moment/locale/en";
let appLocale = NativeModules.SettingsManager.settings.AppleLocale || NativeModules.SettingsManager.settings.AppleLanguages[0];
// remove country portion of locale if (appLocale.indexOf("") > 0) appLocale = appLocale.split("")[0];
console.log("appLocale: " + appLocale);
moment.locale(appLocale); LocalizationConfig(appLocale)
In app.js I also have the import for moment and the specific country codes as above. The localization config will change the locale object depending on whether english or Japanese is the language. As I've said this works great in debug mode in the simulator but no luck in production.
There's a risk that NativeModules.SettingsManager.settings.AppleLocale
and/or AppleLanguages is a value other than ja
or en
. As a test, hard-code your app to moment.locale('ja')
for the production build.
I didn't mean to reply to this issue, sorry. I went back to my main issue. Yes I did hardcode "ja" into there for testing (in production build) since I'm not in Japan and can't get that locale unless I hardcode.
I followed the instructions and something must be wrong that we can't troubleshoot. I may have to leave it english.
I have the similar crash where moment complain that the specified locale passed to the calendar strip prop is not loaded/configured. It turns out that I have 2 different versions of moment, one installed in node_modules/moment
and the other installed in node_modules/react-native-calendar-strip/node_modules/moment
.
Because of this, I got the following behaviours:
moment
configured with our locale is not reflected on RN calendar strip because the library is using its own version of moment
which still uses the default locale.locale
prop does not change the localization inside RN calendar strip because the specified locale is not loaded/configured for the RN calendar strip's moment
.locale
prop results in a crash because the specified locale is not loaded/configured.resolutions
in package.json
:
"resolutions": {
"moment": "^2.29.0"
}
node_modules/react-native-calendar-strip/node_modules/moment
does not exist after running yarn install
.locale
prop.
import moment from 'moment'
import 'moment/locale/vi'
moment.locale('vi')
# The permanent fix
`moment` should be specified as peer dependency inside the library's `package.json`.
This is what I tried: import 'react-native-calendar-strip'; import 'react-native-calendar-strip/node_modules/moment/locale/vi';
Am having issues to configure the lib with 3 languages:
en
,fr
andde
.I have found some issues related to the problem, but none worked for me. Some related issues include #89 #110 & #141.
For me the following elements need clarification:
The
locale.name
usesfr
oren
. Should'nt we use a full language and region code likefr-ch
oren-uk
? This seems to have been discussed on moment.The
locale.name
seems to sometimes require just a language, but sometimes a region too. Depending on moment.js implementation. Seenode_modules/moment/locale/*.js
for a list.locale.config
object : why do we need to pass this as we still import the locale file? Why, if I specify the wholelocale.config
file as a copy of themoment
lib, I still requiremoment
to be imported?While digging for solutions, I have found none that worked. Seeing the amount of issues are related to localization, there seems to be a lack of documentation and maybe some refactoring is required.
My current issue
Am just trying to set that up properly for the 3 languages stated above. I have tried many variants, but based on what I have read in the readme and in the related issues, I should do the following:
Use component as follow:
That does not work and crash on app start on release.
Hypothese
Couldn't be the import something like:
Then the setup of the component like:
Wouldn't that be cleaner and better developer experience?
Who can help me? What can I do to fix this?
Thanks for your help and input!