/
welcome.jsx
385 lines (333 loc) · 14.4 KB
/
welcome.jsx
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
/*
This file is part of Talkie -- text-to-speech browser extension button.
<https://joelpurra.com/projects/talkie/>
Copyright (c) 2016, 2017 Joel Purra <https://joelpurra.com/>
Talkie is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Talkie is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Talkie. If not, see <https://www.gnu.org/licenses/>.
*/
import React from "react";
import PropTypes from "prop-types";
import configureAttribute from "../../../shared/hocs/configure.jsx";
import translateAttribute from "../../../shared/hocs/translate.jsx";
import styled from "../../../shared/hocs/styled.jsx";
import * as layoutBase from "../../../shared/styled/layout/layout-base.jsx";
import * as textBase from "../../../shared/styled/text/text-base.jsx";
import * as listBase from "../../../shared/styled/list/list-base.jsx";
import Discretional from "../../../shared/components/discretional.jsx";
import HeroVersionSection from "../../../shared/components/hero-section/hero-version-section.jsx";
import SharingIcons from "../../../shared/components/sharing/sharing-icons.jsx";
@configureAttribute
@translateAttribute
export default class Welcome extends React.PureComponent {
constructor(props) {
super(props);
this.playWelcomeMessage = this.playWelcomeMessage.bind(this);
this.selectTextInElement = this.selectTextInElement.bind(this);
this.spokeSample = false;
this.welcomeSampleTextElement = null;
this.styled = {
heroDiv: styled({
marginBottom: "2em",
})("div"),
heroVersionSection: styled({
// NOTE: atomic css class ordering seems to not work well in this case.
marginBottom: 0,
})(HeroVersionSection),
sampleHeroP: styled({
marginTop: 0,
})(textBase.p),
welcomeHeroP: styled({
marginTop: 0,
marginBottom: 0,
})(textBase.p),
sharingDiv: styled({
marginTop: "-4em",
marginLeft: "6em",
marginRight: "6em",
})("div"),
sharingIcons: styled({
display: "inline-block",
verticalAlign: "middle",
})(SharingIcons),
summaryHeading: styled({
display: "inline-block",
marginLeft: 0,
marginRight: 0,
marginTop: 0,
marginBottom: 0,
paddingLeft: "0.5em",
paddingRight: "0.5em",
paddingTop: "0.5em",
paddingBottom: "0.5em",
})(textBase.h3),
};
}
static defaultProps = {
isPremiumVersion: false,
systemType: null,
osType: null,
voicesCount: 0,
languagesCount: 0,
languageGroupsCount: 0,
sampleText: null,
sampleTextLanguageCode: null,
speakTextInLanguageWithOverrides: null,
canSpeakInTranslatedLocale: false,
};
static propTypes = {
isPremiumVersion: PropTypes.bool.isRequired,
systemType: PropTypes.string.isRequired,
osType: PropTypes.string,
voicesCount: PropTypes.number.isRequired,
languagesCount: PropTypes.number.isRequired,
languageGroupsCount: PropTypes.number.isRequired,
sampleText: PropTypes.string,
sampleTextLanguageCode: PropTypes.string,
speakTextInLanguageWithOverrides: PropTypes.func.isRequired,
canSpeakInTranslatedLocale: PropTypes.bool.isRequired,
translate: PropTypes.func.isRequired,
configure: PropTypes.func.isRequired,
}
componentDidMount() {
this.playWelcomeMessage();
}
componentDidUpdate() {
this.playWelcomeMessage();
}
playWelcomeMessage() {
if (!this.welcomeSampleTextElement) {
return;
}
if (this.spokeSample) {
return;
}
this.spokeSample = true;
this.selectTextInElement(this.welcomeSampleTextElement);
const welcomeSample = this.getWelcomeSample();
const text = welcomeSample.text;
const languageCode = welcomeSample.languageCode;
this.props.speakTextInLanguageWithOverrides(text, languageCode);
}
selectTextInElement(element) {
const selection = document.getSelection();
selection.removeAllRanges();
selection.selectAllChildren(element);
}
getWelcomeSample() {
const hasSampleText = !!this.props.sampleText;
const welcomeSampleText = this.props.sampleText;
const welcomeSampleTextLanguage = this.props.sampleTextLanguageCode;
const welcomeSample = {
hasSampleText: hasSampleText,
text: welcomeSampleText,
languageCode: welcomeSampleTextLanguage,
};
return welcomeSample;
}
render() {
const {
isPremiumVersion,
systemType,
osType,
voicesCount,
languagesCount,
languageGroupsCount,
canSpeakInTranslatedLocale,
translate,
configure,
} = this.props;
// TODO: configuration.
const devModeShowAll = false;
// TODO: pretty name.
const systemTypePrettyName = systemType;
// TODO: pretty name.
const osTypePrettyName = osType;
const welcomeSample = this.getWelcomeSample();
return (
<section>
<this.styled.heroDiv>
<this.styled.heroVersionSection
isPremiumVersion={isPremiumVersion}
>
<Discretional
enabled={welcomeSample.hasSampleText}
>
<this.styled.sampleHeroP>
<span
lang={welcomeSample.languageCode}
ref={(welcomeSampleTextElement) => {
this.welcomeSampleTextElement = welcomeSampleTextElement;
}}
>
{welcomeSample.text}
</span>
</this.styled.sampleHeroP>
</Discretional>
<this.styled.welcomeHeroP>
{translate("frontend_welcomeHero01", [
translate("extensionShortName"),
])}
<Discretional
enabled={canSpeakInTranslatedLocale}
>
{" "}
{translate("frontend_welcomeHero02")}
</Discretional>
</this.styled.welcomeHeroP>
</this.styled.heroVersionSection>
<this.styled.sharingDiv>
<this.styled.sharingIcons />
<textBase.a href={configure("urls.rate")}>
{translate("frontend_rateIt")}
</textBase.a>
</this.styled.sharingDiv>
</this.styled.heroDiv>
<textBase.h2>
{translate("frontend_welcomeInstallMoreVoicesHeading")}
</textBase.h2>
<textBase.p>
{/* TODO: pretty format */}
{translate("frontend_welcomeInstallMoreVoicesDescription", [
voicesCount,
languageGroupsCount,
languagesCount,
systemTypePrettyName,
osTypePrettyName,
])}
</textBase.p>
<Discretional
enabled={devModeShowAll || osType === "win"}
>
<layoutBase.details>
<layoutBase.summary>
<this.styled.summaryHeading>
{translate("frontend_faq002Q")}
</this.styled.summaryHeading>
</layoutBase.summary>
{/* NOTE: this entry are duplicated between the support FAQ and welcome pages. */}
<textBase.p>
{translate("frontend_faq002A")}
</textBase.p>
<listBase.ul>
<listBase.li>
<textBase.a
href="https://support.office.com/en-us/article/How-to-download-Text-to-Speech-languages-for-Windows-10-d5a6b612-b3ae-423f-afa5-4f6caf1ec5d3"
lang="en"
>
Windows 10
</textBase.a>
</listBase.li>
<listBase.li>
<textBase.a
href="https://support.office.com/en-us/article/How-to-download-Text-to-Speech-languages-for-Windows-4c83a8d8-7486-42f7-8e46-2b0fdf753130"
lang="en"
>
Windows 8
</textBase.a>
</listBase.li>
<listBase.li>
<textBase.a
href="https://www.microsoft.com/en-us/download/details.aspx?id=27224"
lang="en"
>
Windows 7
</textBase.a>
</listBase.li>
<listBase.li>
<textBase.a
href="http://espeak.sourceforge.net"
lang="en"
>
eSpeak (open source)
</textBase.a>
</listBase.li>
</listBase.ul>
</layoutBase.details>
</Discretional>
<Discretional
enabled={devModeShowAll || osType === "cros"}
>
<layoutBase.details>
<layoutBase.summary>
<this.styled.summaryHeading>
{translate("frontend_faq003Q")}
</this.styled.summaryHeading>
</layoutBase.summary>
{/* NOTE: this entry are duplicated between the support FAQ and welcome pages. */}
<textBase.p>
{translate("frontend_faq003A")}
</textBase.p>
<listBase.ul>
<listBase.li>
<textBase.a
href="https://chrome.google.com/webstore/detail/us-english-female-text-to/pkidpnnapnfgjhfhkpmjpbckkbaodldb"
lang="en"
>
US English Female Text-to-speech (by Google)
</textBase.a>
</listBase.li>
</listBase.ul>
</layoutBase.details>
</Discretional>
<Discretional
enabled={devModeShowAll || osType === "mac"}
>
<layoutBase.details>
<layoutBase.summary>
<this.styled.summaryHeading>
{translate("frontend_faq004Q")}
</this.styled.summaryHeading>
</layoutBase.summary>
{/* NOTE: this entry are duplicated between the support FAQ and welcome pages. */}
<textBase.p>
{translate("frontend_faq004A")}
</textBase.p>
<listBase.ul>
<listBase.li>
<textBase.a
href="https://support.apple.com/kb/PH25378"
lang="en"
>
macOS Sierra (10.12)
</textBase.a>
</listBase.li>
</listBase.ul>
</layoutBase.details>
</Discretional>
<Discretional
enabled={devModeShowAll || osType === "linux"}
>
<layoutBase.details>
<layoutBase.summary>
<this.styled.summaryHeading>
{translate("frontend_faq005Q")}
</this.styled.summaryHeading>
</layoutBase.summary>
{/* NOTE: this entry are duplicated between the support FAQ and welcome pages. */}
<textBase.p>
{translate("frontend_faq005A")}
</textBase.p>
<listBase.ul>
<listBase.li>
<textBase.a
href="http://espeak.sourceforge.net"
lang="en"
>
eSpeak (open source)
</textBase.a>
</listBase.li>
</listBase.ul>
</layoutBase.details>
</Discretional>
</section>
);
}
}