react-native-gifted-chat icon indicating copy to clipboard operation
react-native-gifted-chat copied to clipboard

Locale doesn't work

Open dan-arkhipov opened this issue 5 years ago • 12 comments

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

dan-arkhipov avatar Aug 21 '20 00:08 dan-arkhipov

@xcarpentier I know you have done PR for this, any ideas?

dan-arkhipov avatar Aug 21 '20 00:08 dan-arkhipov

import ru 'dayjs/locale/ru

render (
     <GiftedChat messages={messages} locale={ru} />
)

this works but warning : locale must be string

erhanersoz avatar Aug 21 '20 21:08 erhanersoz

@erhanersoz getting syntax error, can you double-check the code you have provided?

dan-arkhipov avatar Aug 22 '20 13:08 dan-arkhipov

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} />
)

dan-arkhipov avatar Aug 22 '20 13:08 dan-arkhipov

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.

stale[bot] avatar Sep 22 '20 13:09 stale[bot]

@dan-arkhipov Do I need to delete existing chats for this to work?

YannikSood avatar Jan 26 '21 04:01 YannikSood

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.

c-goettert avatar Mar 12 '21 13:03 c-goettert

It is working when enter the locale as string but you need to refresh your app. Hot reload doesn't work.

ErtugrulBEKTIK avatar Jun 26 '21 14:06 ErtugrulBEKTIK

import 'dayjs/locale/he'
...
<GiftedChat
  locale='he'
...
   />

jackwullems avatar Sep 20 '21 08:09 jackwullems

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}
...
/>

borgogelli avatar Jun 08 '23 08:06 borgogelli

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

bitlab-code avatar Sep 21 '23 22:09 bitlab-code

I succeeded once a long time ago. But I can't change it recently, I have used all the methods above.

rento666 avatar Feb 16 '24 08:02 rento666