-
Notifications
You must be signed in to change notification settings - Fork 523
/
Editor.js
146 lines (131 loc) · 4.61 KB
/
Editor.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/* @flow */
import * as React from 'react';
import { Localized } from 'fluent-react';
import './Editor.css';
import { PluralSelector } from 'core/plural';
import EditorProxy from './EditorProxy';
import EditorSettings from './EditorSettings';
import KeyboardShortcuts from './KeyboardShortcuts';
import type { Locale } from 'core/locales';
import type { UserState } from 'core/user';
import type { DbEntity } from 'modules/entitieslist';
type Props = {|
translation: string,
entity: ?DbEntity,
locale: Locale,
pluralForm: number,
user: UserState,
sendTranslation: () => void,
updateEditorTranslation: (string) => void,
updateSetting: (string, boolean) => void,
|};
type State = {|
translation: string,
|};
/**
* Editor for translation strings.
*
* Will present a different editor depending on the file format of the string,
* see `EditorProxy` for more information.
*/
export default class Editor extends React.Component<Props, State> {
componentDidUpdate(prevProps: Props) {
if (this.props.translation !== prevProps.translation) {
this.updateTranslation(this.props.translation);
}
}
updateTranslation = (translation: string) => {
this.props.updateEditorTranslation(translation);
}
copyOriginalIntoEditor = () => {
const { entity, pluralForm } = this.props;
if (entity) {
if (pluralForm === -1 || pluralForm === 1) {
this.updateTranslation(entity.original);
}
else {
this.updateTranslation(entity.original_plural);
}
}
}
clearEditor = () => {
this.updateTranslation('');
}
sendTranslation = () => {
this.props.sendTranslation();
}
render() {
return <div className="editor">
<PluralSelector />
<EditorProxy
entity={ this.props.entity }
translation={ this.props.translation }
locale={ this.props.locale }
updateTranslation={ this.updateTranslation }
/>
<menu>
{ !this.props.user.isAuthenticated ?
<Localized
id="editor-editor-sign-in-to-translate"
a={
/* eslint-disable-next-line */
<a href='/accounts/fxa/login/?scope=profile%3Auid+profile%3Aemail+profile%3Adisplay_name'></a>
}
>
<p className='banner'>
{ '<a>Sign in</a> to translate.' }
</p>
</Localized>
:
<React.Fragment>
<EditorSettings
settings={ this.props.user.settings }
updateSetting={ this.props.updateSetting }
/>
<KeyboardShortcuts />
<div className="actions">
<Localized id="editor-editor-button-copy">
<button
className="action-copy"
onClick={ this.copyOriginalIntoEditor }
>
Copy
</button>
</Localized>
<Localized id="editor-editor-button-clear">
<button
className="action-clear"
onClick={ this.clearEditor }
>
Clear
</button>
</Localized>
{ this.props.user.settings.forceSuggestions ?
// Suggest button, will send an unreviewed translation.
<Localized id="editor-editor-button-suggest">
<button
className="action-suggest"
onClick={ this.sendTranslation }
>
Suggest
</button>
</Localized>
:
// Save button, will send an approved translation.
<Localized id="editor-editor-button-save">
<button
className="action-save"
onClick={ this.sendTranslation }
>
Save
</button>
</Localized>
}
</div>
<div className="clearfix" />
</React.Fragment>
}
</menu>
</div>;
}
}