<commit_before>import {updateIntl} from 'react-intl-redux'

export default class Intl {
  static initIntl(store, moduleName) {
    return Intl.getUserInfo()
      .then(userInfo => Intl.loadTextResources(userInfo.locale, moduleName)
        .then(textResources => store.dispatch(updateIntl(
          {
            locale: userInfo.locale.replace('_', '-'),
            messages: textResources
          }
          ))
        ))
  }

  static getUserInfo() {
    if (__DEV__) {
      console.log('would fetch userinfo')
      return new Promise(resolve => resolve({
        locale: 'de-CH'
      }))
    }
    return fetch(`${__BACKEND_URL__}/nice2/username`)
      .then(response => response.json())
  }

  static loadTextResources(locale, moduleName) {
    if (__DEV__) {
      console.log('would fetch textresources')
      return new Promise(resolve => resolve({
        testKey: 'das ist ein test'
      }))
    }
    return fetch(`${__BACKEND_URL__}/nice2/textresource?locale=${locale}${moduleName ? `&module=${moduleName}` : ''}`)
      .then(response => response.json())
  }
}<commit_msg>feat(tocco-util): Introduce Intl#setLocale() to set a new locale<commit_after>import {updateIntl} from 'react-intl-redux'

export default class Intl {

  static initIntl(store, moduleName, locale) {
    const loadLocale = locale
      ? Promise.resolve(locale)
      : Intl.getUserInfo().then(userInfo => Promise.resolve(userInfo.locale))
    return loadLocale.then(locale => Intl.setLocale(store, moduleName, locale))
  }

  static setLocale(store, moduleName, locale) {
    Intl.loadTextResources(locale, moduleName)
      .then(textResources => store.dispatch(updateIntl({
        locale: locale.replace('_', '-'),
        messages: textResources
      })))
  }

  static getUserInfo() {
    if (__DEV__) {
      console.log('would fetch userinfo')
      return new Promise(resolve => resolve({
        locale: 'de-CH'
      }))
    }
    return fetch(`${__BACKEND_URL__}/nice2/username`)
      .then(response => response.json())
  }

  static loadTextResources(locale, moduleName) {
    if (__DEV__) {
      console.log('would fetch textresources')
      const testResources = {
        'de-CH': {
          testKey: 'das ist ein test'
        },
        en: {
          testKey: 'this is a test'
        }
      }
      return new Promise(resolve => resolve(testResources[locale]))
    }
    return fetch(`${__BACKEND_URL__}/nice2/textresource?locale=${locale}${moduleName ? `&module=${moduleName}` : ''}`)
      .then(response => response.json())
  }
}
{'fraction_non_alphanumeric': 0.1416829745596869, 'fraction_numerical': 0.0015655577299412916, 'mean_word_length': 2.884498480243161, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 16, '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': '5405804', 'n_tokens_mistral': 779, 'n_tokens_neox': 764, 'n_words': 151}