Locale doesn't work
Issue Description
Locale doesn't work. As per instruction in README, I am setting dayjs locale but still not getting any dates/time localized. Any ideas?
import 'dayjs/locale/ru
render (
<GiftedChat messages={messages} locale={'ru'} />
)
Steps to Reproduce / Code Snippets
As above
Expected Results
Dates and times localized to a selected locale
Additional Information
- Nodejs version: 13
- React version:16.8.1
- React Native version:0.61.3
- react-native-gifted-chat version: 0.16.3
- Platform(s) (iOS, Android, or both?):both
- TypeScript version: N/A
@xcarpentier I know you have done PR for this, any ideas?
import ru 'dayjs/locale/ru
render (
<GiftedChat messages={messages} locale={ru} />
)
this works but warning : locale must be string
@erhanersoz getting syntax error, can you double-check the code you have provided?
OK, managed to sort this, this is what worked for me:
const dayjs = require('dayjs');
import ru from 'dayjs/locale/ru'
render (
<GiftedChat messages={messages} locale={ru} />
)
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
@dan-arkhipov Do I need to delete existing chats for this to work?
Eventhough the solution suggested by @dan-arkhipov works for me, I think this issue should not be closed until the docs have been updated. Also, I get an console error because of the mismatching proptype:
Failed prop type: Invalid prop `locale` of type `object` supplied to `GiftedChat`, expected `string`.
Either there is a bug that the locale prop does not work as documented, or the documentation and prop-types are not correct.
It is working when enter the locale as string but you need to refresh your app. Hot reload doesn't work.
import 'dayjs/locale/he'
...
<GiftedChat
locale='he'
...
/>
import 'dayjs/locale/it' ... <GiftedChat locale='it' ... />
Doesn't work for me. I agree with the @c-goettert's comment, so the following code works but returns the error:
Invalid prop localeof typeobjectsupplied toGiftedChat, expected string.
import it from '../locale/dayjs/it';
...
<GiftedChat
locale={it}
...
/>
This is a bug but it works thanks to DayJs and because react-native-gifted-chat doesn't do any checks.
in react-native-gifted-chat getLocale return a string
dayjs(currentMessage.createdAt).locale(getLocale()).format(timeFormat)
bat luckily, DayJs accept also ILocale
locale(preset: string | ILocale, object?: Partial<ILocale>): Dayjs
NB: This is a 3 year old issue!! and I think many developers use this workaround, what if this bug is fixed without keeping this fact in mind? maybe the best type for locale prop is string | ILocale
I succeeded once a long time ago. But I can't change it recently, I have used all the methods above.