modules/core/localize/LocalizedComponent.js   A
last analyzed

Complexity

Total Complexity 2
Complexity/F 1

Size

Lines of Code 48
Function Count 2

Duplication

Duplicated Lines 0
Ratio 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
eloc 40
mnd 0
bc 0
fnc 2
dl 0
loc 48
ccs 10
cts 10
cp 1
bpm 0
cpm 1
noi 0
c 0
b 0
f 0
rs 10

2 Functions

Rating   Name   Duplication   Size   Complexity  
A LocalizedComponent.render 0 3 1
A LocalizedComponent.componentDidMount 0 4 1
1
import React from 'react'
2
import PropTypes from 'prop-types'
3
import { renderToStaticMarkup } from 'react-dom/server'
4
import { withLocalize } from 'react-localize-redux'
5
import enTrans from '~/public/translations/en.json'
6
import vnTrans from '~/public/translations/vn.json'
7
import { EN } from '~/modules/home/consts/langs'
8
9 1
const defaultLanguage = EN
10
11
class LocalizedComponent extends React.Component {
12
  constructor(props) {
13 1
    super(props)
14
15 1
    const languages = ['en', 'vn']
16
17 1
    this.props.initialize({
18
      languages,
19
      options: {
20
        renderToStaticMarkup,
21
        defaultLanguage,
22
        renderInnerHtml: true
23
      }
24
    })
25
26 1
    this.props.addTranslationForLanguage(enTrans, 'en')
27 1
    this.props.addTranslationForLanguage(vnTrans, 'vn')
28
  }
29
30
  render() {
31 1
    return this.props.children
32
  }
33
34
  componentDidMount() {
35 2
    const lang = window.localStorage.getItem('lang') || defaultLanguage
36 1
    this.props.setActiveLanguage(lang)
37
  }
38
}
39
40 1
LocalizedComponent.propTypes = {
41
  initialize: PropTypes.func,
42
  addTranslationForLanguage: PropTypes.func,
43
  children: PropTypes.element,
44
  setActiveLanguage: PropTypes.func
45
}
46
47
export default withLocalize(LocalizedComponent)
48