/
index.js
78 lines (71 loc) · 1.84 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import TextDiff from '../TextDiff'
import React, { PropTypes } from 'react'
import cx from 'classnames'
/**
* Display all content strings (singular or plurals) for a suggestion.
* May show a diff against a set of provided strings.
*/
const SuggestionContents = React.createClass({
propTypes: {
plural: PropTypes.bool.isRequired,
contents: PropTypes.arrayOf(
PropTypes.string
).isRequired,
// Include this to display a diff
compareTo: PropTypes.arrayOf(
PropTypes.string
)
},
pluralFormLabel: function (index) {
if (this.props.plural) {
// FIXME translate the text. Either:
// - get it from Angular Gettext
// - use react-intl for it
const text = index ? 'Plural Form' : 'Singular Form'
return (
<span className="u-textMeta">
{text}
</span>
)
}
},
/* Simple or diff content, depending whether props.compareTo
* is present.
*/
contentDiv: function (content, index) {
const compareTo = this.props.compareTo
const className = cx(
'TransUnit-text',
{
'TransUnit-text--tight': !this.props.plural,
'Difference': compareTo
}
)
return compareTo
? <TextDiff
className={className}
text1={index >= compareTo.length ? '' : compareTo[index]}
text2={content} />
: <div className={className}>
{content}
</div>
},
render: function () {
const contents = this.props.contents.map((content, index) => {
return (
<div key={index} className="TransUnit-item">
<div className="TransUnit-itemHeader">
{this.pluralFormLabel(index)}
</div>
{this.contentDiv(content, index)}
</div>
)
})
return (
<div>
{contents}
</div>
)
}
})
export default SuggestionContents