Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Locale prop no longer working #762

Closed
jaaberg opened this issue Feb 21, 2018 · 10 comments
Closed

Locale prop no longer working #762

jaaberg opened this issue Feb 21, 2018 · 10 comments

Comments

@jaaberg
Copy link

jaaberg commented Feb 21, 2018

Issue Description

The prop locale doesn't seem to work anymore for the time separators in the chat.

Steps to Reproduce / Code Snippets

You find it here: https://snack.expo.io/SJD3c-swG

import React, { Component } from 'react';
import { View } from 'react-native';
import { GiftedChat } from 'react-native-gifted-chat' // 0.3.0

export default class App extends Component {
  render() {
    const userId= '123';
    const messages = [{
      _id: '1',
      createdAt: 1519225196922,
      text: 'Hello',
      user: {
        _id: userId,
        name: "Name",
      },
    }]
    return (
      <View style={{flex:1}}>
        <GiftedChat
          messages={messages}
          user={{ _id: userId }}
          dateFormat={'dddd DD. MMMM'}
          locale={'nb'}
        />
      </View>
    );
  }
}

Expected Results

That the time separator should be in norwegian (according to locale prop)

Additional Information

  • Nodejs version: 7.5.0
  • React version: 16.2.0
  • React Native version: 0.52
  • react-native-gifted-chat version: 0.3.0
  • Platform(s) (iOS, Android, or both?): At least on iOS (haven't tested android)
@mafiusu
Copy link

mafiusu commented Feb 21, 2018

Having the same issue. But it's working if you import this

import "moment";
import "moment/locale/nb";

@jaaberg
Copy link
Author

jaaberg commented Feb 22, 2018

Doesn't seem to work for me :/

@xcarpentier xcarpentier added this to To do in Release 0.4.0 Feb 23, 2018
@xcarpentier
Copy link
Collaborator

xcarpentier commented Feb 23, 2018

@jaaberg
It seem you are right.
But I don't figured out why for now...

Did you try to set locale too?

import "moment/locale/nb"

// add new locale to global
moment.locale('nb')

// log locales
console.log(moment.locales())

@jaaberg
Copy link
Author

jaaberg commented Feb 23, 2018

Oh, found it,

I have used a different version of moment, 2.18.1, and react-native-gifted-chat uses ^2.19.0. This creates two different instances, so it doesn't mather if I import locales in my project. But if I change to same version in my project, it works if I just add import "moment/locale/nb".

Moment should probably be a peerDependency, or import the languages itself. Want a PR for moving it to peerDependency? :)

@xcarpentier
Copy link
Collaborator

Yes please :)

@stale
Copy link

stale bot commented Feb 12, 2019

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 stale bot added the wontfix label Feb 12, 2019
@stale stale bot closed this as completed Feb 19, 2019
@vandrieu
Copy link

Hello,
Here is how I fixed it in my local environment, but it's just a workaround, any "npm install" from scratch will erase your changes.

  1. Open node_modules/react-native-gifted-chat/src/Day.js

  2. Replace that import:

import moment from 'moment';

With that :

import moment from 'moment/min/moment-with-locales';
moment.locale('<your locale>');
  1. Still in Day.js, replace
            {moment(currentMessage.createdAt)
              .locale(context.getLocale())
              .format(dateFormat)
              .toUpperCase()}

with

            {moment(currentMessage.createdAt)
              .format(dateFormat)
              .toUpperCase()}
  1. Now it works (as a temporary workaround)

@r1ckyrockz
Copy link
Contributor

Please reopen this issue, because it it not yet solved.

My environment:

NodeJS: 12.4.0
react: 16.8.6
react-native: 0.60.3
react-native-gifted-chat: ^0.9.11
moment: 2.19.0 || 2.24.0 // take no effect

@msqar
Copy link

msqar commented Feb 21, 2020

Any update on this? It's still failing for me.

@xcarpentier
Copy link
Collaborator

#1397 we will use dayjs instead

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Release 0.4.0
  
Done
Development

No branches or pull requests

6 participants