<commit_before>import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import numeral from 'numeral';
import { addLocaleData, IntlProvider } from 'react-intl';
import 'numeral/locales/fr';
import 'numeral/locales/es';
import fr from 'react-intl/locale-data/fr';
import en from 'react-intl/locale-data/en';
import es from 'react-intl/locale-data/es';
import enTranslations from '../translations/en.json';
import frTranslations from '../translations/fr.json';
import esTranslations from '../translations/es.json';
import { changeLocale } from '../actions/locale';

export const availableLocales = [{
  label: 'English',
  tag: 'en',
}, {
  label: 'Espanol',
  tag: 'es',
}, {
  label: 'Francais',
  tag: 'fr',
}];

addLocaleData(en);
addLocaleData(fr);
addLocaleData(es);

const MESSAGES = {
  fr: frTranslations,
  es: esTranslations,
  en: enTranslations,
};

const getMessages = (locale = 'en') => MESSAGES[locale];

class IntlWrapper extends Component {

  constructor(props) {
    super(props);
    this.state = {
      abbrNumber: value => numeral(value).format('0.0a'),
      messages: getMessages(props.locale),
    };
  }

  getChildContext() {
    const { abbrNumber } = this.state;
    return { abbrNumber };
  }

  componentDidMount() {
    const { locale } = this.props;
    this.handleChangeLocale(locale);
  }

  UNSAFE_componentWillReceiveProps(nextProps) {
    const { locale } = this.props;
    if (locale !== nextProps.locale) {
      this.handleChangeLocale(nextProps.locale);
    }
  }

  handleChangeLocale(locale) {
    if (!locale) return;

    numeral.locale(locale);

    this.setState({
      messages: getMessages(locale),
    });

    this.props.dispatch(changeLocale(locale));
  }

  render() {
    const { children, locale } = this.props;
    return (
      <IntlProvider key={locale} locale={locale} messages={this.state.messages}>
        {children}
      </IntlProvider>
    );<commit_msg>[#2569] Adapt UNSAFE_componentWillReceiveProps<commit_after>import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import numeral from 'numeral';
import { addLocaleData, IntlProvider } from 'react-intl';
import 'numeral/locales/fr';
import 'numeral/locales/es';
import fr from 'react-intl/locale-data/fr';
import en from 'react-intl/locale-data/en';
import es from 'react-intl/locale-data/es';
import enTranslations from '../translations/en.json';
import frTranslations from '../translations/fr.json';
import esTranslations from '../translations/es.json';
import { changeLocale } from '../actions/locale';

export const availableLocales = [{
  label: 'English',
  tag: 'en',
}, {
  label: 'Espanol',
  tag: 'es',
}, {
  label: 'Francais',
  tag: 'fr',
}];

addLocaleData(en);
addLocaleData(fr);
addLocaleData(es);

const MESSAGES = {
  fr: frTranslations,
  es: esTranslations,
  en: enTranslations,
};

const getMessages = (locale = 'en') => MESSAGES[locale];

class IntlWrapper extends Component {

  constructor(props) {
    super(props);
    this.state = {
      abbrNumber: value => numeral(value).format('0.0a'),
      messages: getMessages(props.locale),
      locale: props.locale,
    };
  }

  getChildContext() {
    const { abbrNumber } = this.state;
    return { abbrNumber };
  }

  componentDidMount() {
    const { locale } = this.props;
    this.handleChangeLocale(locale);
  }

  componentDidUpdate(prevProps, prevState) {
    if (prevState.locale !== this.state.locale) {
      this.handleChangeLocale(this.state.locale);
    }
  }

  static getDerivedStateFromProps(nextProps, prevState) {
    if (nextProps.locale !== prevState.locale) {
      return {
        messages: getMessages(nextProps.locale),
        locale: nextProps.locale,
      };
    }
    return null;
  }

  handleChangeLocale(locale) {
    if (!locale) return;
    numeral.locale(locale);
    this.props.dispatch(changeLocale(locale));
  }

  render() {
    const { children, locale } = this.props;
    return (
      <IntlProvider key={locale} locale={locale} messages={this.state.messages}>
        {children}
      </IntlProvider>
    );
{'fraction_non_alphanumeric': 0.14641744548286603, 'fraction_numerical': 0.001917086029235562, 'mean_word_length': 3.679372197309417, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3382766', 'n_tokens_mistral': 1370, 'n_tokens_neox': 1343, 'n_words': 286}