React-native-gifted-chat: How to display German time with locale?

Created on 13 Nov 2017  路  5Comments  路  Source: FaridSafi/react-native-gifted-chat

Issue Description

Hello I know that gifted chat supports Localized dates. I have tried to set the locale property to the gifted messenger with "de" to displaying German time without AM/PM. But this is not working. Anyone tried to change the time to German?

Steps to Reproduce / Code Snippets

<GiftedChat placeholder="Nachricht verfassen ..." messages={this.state.messages} onSend={this.onSend} locale="de" loadEarlier={this.state.loadEarlier} onLoadEarlier={this.onLoadEarlier} isLoadingEarlier={this.state.isLoadingEarlier} user={user} onInputTextChanged={this.onTyping} maxInputLength={200} renderFooter={this.renderFooter} renderActions={this.renderCustomActions} renderCustomView={this.renderCustomView} renderSystemMessage={this.renderSystemMessage} />

Additional Information

  • React Native version: react-native-cli: 2.0.1 react-native: 0.49.5
  • react-native-gifted-chat version: latest
  • Platform(s) (iOS, Android, or both?): iOS

Most helpful comment

Just faced the same issue. Be sure to load moment and your moment locale at startup before rendering GiftedChat:
index.js:

import "moment";
import "moment/locale/de";

All 5 comments

Just faced the same issue. Be sure to load moment and your moment locale at startup before rendering GiftedChat:
index.js:

import "moment";
import "moment/locale/de";

Somehow this doesn't work for me. Even if I import the locale in my component, inside of GiftedChat only en is available through moment.locales()

It only works after I modify GiftedChat.js and explicitly add import 'moment/locale/de' in the imports. Not sure why the locale doesn't get passed down to the GiftedChat component.

None of this works for me

Yep, also doesn't work here
rn 0.49.3
gifted 0.2.9
moment 2.21.0

moment.locales() after app start -> ["en", "en-gb", "zh-cn", "zh-hk"]
moment.locale() -> zh-hk
<GiftedChat ... locale={'zh-hk'} />

Import with

import moment from 'moment/min/moment-with-locales';

and call the following function before rendering GiftedChat with your chosen locale prop. (i.e. in componentWillMount())

moment.locale(YOUR_LOCALE_IDENTIFIER);

Was this page helpful?
0 / 5 - 0 ratings