<commit_before>import React, { Component, PropTypes } from 'react'
import ReactDOM from 'react-dom'
import counterpart from 'counterpart'
import { fixLocaleName } from 'shared/utils/locale-utils'
import moment from 'moment'
import 'moment/locale/zh-tw'
import 'moment/locale/zh-cn'

// Great thanks to kikoanis (<NAME>), https://github.com/kikoanis
export default function connectI18n(handler) {
  return function(ComposedComponent) {
    return class Wrapper extends Component {

      static contextTypes = {
        translator: PropTypes.object
      }

      constructor (props) {
        super(props)

        this.state = { defaultLocale: this.getLocale() }
      }

      componentWillMount () {
        moment.locale(fixLocaleName(this.getLocale()))
      }

      componentDidMount () {
        counterpart.onLocaleChange(this.handleLocaleChange)
      }

      componentWillUnmount () {
        counterpart.offLocaleChange(this.handleLocaleChange)
      }

      getLocale = () => {
        if (typeof this.context !== 'undefined'
          && typeof this.context.translator !== 'undefined') {
          return this.context.translator.getLocale()
        } else {
          return counterpart.getLocale()
        }<commit_msg>fixed server side rendering locale issues<commit_after>import React, { Component, PropTypes } from 'react'
import ReactDOM from 'react-dom'
import counterpart from 'counterpart'
import { fixLocaleName } from 'shared/utils/locale-utils'
import moment from 'moment'
import 'moment/locale/zh-tw'
import 'moment/locale/zh-cn'

// Great thanks to kikoanis (<NAME>), https://github.com/kikoanis
export default function connectI18n(handler) {
  return function(ComposedComponent) {
    return class Wrapper extends Component {

      static contextTypes = {
        translator: PropTypes.object
      }

      constructor (props, context) {
        super(props)

        if (typeof context !== 'undefined'
          && typeof context.translator !== 'undefined') {
          this.state = { defaultLocale: context.translator.getLocale() }
        } else {
          this.state = { defaultLocale: counterpart.getLocale() }
        }
      }

      componentWillMount () {
        moment.locale(fixLocaleName(this.state.defaultLocale))
      }

      componentDidMount () {
        counterpart.onLocaleChange(this.handleLocaleChange)
      }

      componentWillUnmount () {
        counterpart.offLocaleChange(this.handleLocaleChange)
{'fraction_non_alphanumeric': 0.10569105691056911, 'fraction_numerical': 0.0016260162601626016, 'mean_word_length': 2.9565916398713825, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 6, 'https://': 2, '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': '3822541', 'n_tokens_mistral': 672, 'n_tokens_neox': 653, 'n_words': 148}