Skip to content

Commit 2ec69f1

Browse files
authored
Merge pull request #3382 from chrisgarrity/feature/3230-translate-videos
Add video translation
2 parents 41fc932 + 2bf7c91 commit 2ec69f1

File tree

5 files changed

+137
-16
lines changed

5 files changed

+137
-16
lines changed

src/components/cards/cards.jsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import leftArrow from './icon--prev.svg';
1111
import helpIcon from '../../lib/assets/icon--tutorials.svg';
1212
import closeIcon from '../close-button/icon--close.svg';
1313

14+
import {translateVideo} from '../../lib/libraries/decks/translate-video.js';
15+
1416
const CardHeader = ({onCloseCards, onShowAll, totalSteps, step}) => (
1517
<div className={styles.headerButtons}>
1618
<div
@@ -213,6 +215,7 @@ const Cards = props => {
213215
content,
214216
dragging,
215217
isRtl,
218+
locale,
216219
onActivateDeckFactory,
217220
onCloseCards,
218221
onDrag,
@@ -264,7 +267,7 @@ const Cards = props => {
264267
steps[step].video ? (
265268
<VideoStep
266269
dragging={dragging}
267-
video={steps[step].video}
270+
video={translateVideo(steps[step].video, locale)}
268271
/>
269272
) : (
270273
<ImageStep
@@ -300,7 +303,8 @@ Cards.propTypes = {
300303
})
301304
}),
302305
dragging: PropTypes.bool.isRequired,
303-
isRtl: PropTypes.bool,
306+
isRtl: PropTypes.bool.isRequired,
307+
locale: PropTypes.string.isRequired,
304308
onActivateDeckFactory: PropTypes.func.isRequired,
305309
onCloseCards: PropTypes.func.isRequired,
306310
onDrag: PropTypes.func,

src/containers/cards.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ const mapStateToProps = state => ({
2424
x: state.scratchGui.cards.x,
2525
y: state.scratchGui.cards.y,
2626
isRtl: state.locales.isRtl,
27+
locale: state.locales.locale,
2728
dragging: state.scratchGui.cards.dragging
2829
});
2930

src/lib/libraries/decks/index.jsx

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export default {
7474

7575
img: libraryIntro,
7676
steps: [{
77-
video: 'rpjvs3v9gj'
77+
video: 'intro-move-sayhello'
7878
}, {
7979
title: (
8080
<FormattedMessage
@@ -112,7 +112,7 @@ export default {
112112
),
113113
img: libraryAnimate,
114114
steps: [{
115-
video: 'pyur30ho05'
115+
video: 'animate-a-name'
116116
}, {
117117
title: (
118118
<FormattedMessage
@@ -186,7 +186,7 @@ export default {
186186
),
187187
img: libraryMakeMusic,
188188
steps: [{
189-
video: 'ir0j8ljsgm'
189+
video: 'Make-Music'
190190
},
191191
{
192192
title: (
@@ -254,7 +254,7 @@ export default {
254254
),
255255
img: libraryMakeAGame,
256256
steps: [{
257-
video: '5rp47ys13g'
257+
video: 'Make-A-Game'
258258
},
259259
{
260260
title: (
@@ -340,7 +340,7 @@ export default {
340340
),
341341
img: libraryChaseGame,
342342
steps: [{
343-
video: 'kusyx9thl5'
343+
video: 'Chase-Game'
344344
},
345345
{
346346
title: (
@@ -471,7 +471,7 @@ export default {
471471
),
472472
img: addBackdropThumb,
473473
steps: [{
474-
video: 'nict6zdzlx'
474+
video: 'add-a-backdrop'
475475
}, {
476476
deckIds: [
477477
'change-size',
@@ -490,7 +490,7 @@ export default {
490490
),
491491
img: changeSizeThumb,
492492
steps: [{
493-
video: 'p8va85hh61'
493+
video: 'change-size'
494494
}, {
495495
deckIds: [
496496
'glide-around',
@@ -509,7 +509,7 @@ export default {
509509
),
510510
img: glideAroundThumb,
511511
steps: [{
512-
video: 'sh9j978rg8'
512+
video: 'glide-around'
513513
}, {
514514
deckIds: [
515515
'add-a-backdrop',
@@ -529,7 +529,7 @@ export default {
529529
),
530530
img: recordASound,
531531
steps: [{
532-
video: 'ulzl1fbzny'
532+
video: 'record-a-sound'
533533
}, {
534534
deckIds: [
535535
'Make-Music',
@@ -548,7 +548,7 @@ export default {
548548
),
549549
img: spinThumb,
550550
steps: [{
551-
video: '07fed5hhpv'
551+
video: 'spin-video'
552552
}, {
553553
deckIds: [
554554
'add-a-backdrop',
@@ -567,7 +567,7 @@ export default {
567567
),
568568
img: hideAndShowThumb,
569569
steps: [{
570-
video: 'g479ahobo9'
570+
video: 'hide-and-show'
571571
}, {
572572
deckIds: [
573573
'add-a-backdrop',
@@ -587,7 +587,7 @@ export default {
587587
),
588588
img: switchCostumeThumb,
589589
steps: [{
590-
video: '1ocp6a1ejn'
590+
video: 'switch-costume'
591591
}, {
592592
deckIds: [
593593
'add-a-backdrop',
@@ -607,7 +607,7 @@ export default {
607607
),
608608
img: moveArrowKeysThumb,
609609
steps: [{
610-
video: 'yetrmk4iuu'
610+
video: 'move-around-with-arrow-keys'
611611
}, {
612612
deckIds: [
613613
'add-a-backdrop',
@@ -626,7 +626,7 @@ export default {
626626
),
627627
img: addEffectsThumb,
628628
steps: [{
629-
video: '3jvl8zgjo2'
629+
video: 'add-effects'
630630
}, {
631631
deckIds: [
632632
'add-a-backdrop',
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
/**
2+
* @fileoverview
3+
* Utility function to look up whether a translated video exists for a locale.
4+
*/
5+
6+
// TODO: ja-Hira are copies of ja, replace with real ja-Hira when available.
7+
const videos = {
8+
'intro-move-sayhello': {
9+
'en': 'rpjvs3v9gj',
10+
'ja': 'v2c2f3y2sc',
11+
'ja-Hira': 'v2c2f3y2sc'
12+
},
13+
'animate-a-name': {
14+
'en': 'pyur30ho05',
15+
'ja': 'xrmgno02th',
16+
'ja-Hira': 'xrmgno02th'
17+
},
18+
'Make-Music': {
19+
'en': 'ir0j8ljsgm',
20+
'ja': 'iybhyobckr',
21+
'ja-Hira': 'iybhyobckr'
22+
},
23+
'Make-A-Game': {
24+
'en': '5rp47ys13g',
25+
'ja': 'h4q2ea3ojw',
26+
'ja-Hira': 'h4q2ea3ojw'
27+
},
28+
'Chase-Game': {
29+
'en': 'kusyx9thl5',
30+
'ja': 'wr6ysk8s6d',
31+
'ja-Hira': 'wr6ysk8s6d'
32+
},
33+
'add-a-backdrop': {
34+
'en': 'nict6zdzlx',
35+
'ja': 'j382ohngg7',
36+
'ja-Hira': 'j382ohngg7'
37+
},
38+
'change-size': {
39+
'en': 'p8va85hh61',
40+
'ja': 'uzkfi9uai0',
41+
'ja-Hira': 'uzkfi9uai0'
42+
},
43+
'glide-around': {
44+
'en': 'sh9j978rg8',
45+
'ja': 'jsat4vhu48',
46+
'ja-Hira': 'jsat4vhu48'
47+
},
48+
'record-a-sound': {
49+
'en': 'ulzl1fbzny',
50+
'ja': '5zmy6u614k',
51+
'ja-Hira': '5zmy6u614k'
52+
},
53+
'spin-video': {
54+
'en': '07fed5hhpv',
55+
'ja': 'hjhc0a8r7j',
56+
'ja-Hira': 'hjhc0a8r7j'
57+
},
58+
'hide-and-show': {
59+
'en': 'g479ahobo9',
60+
'ja': 'ruynguvag5',
61+
'ja-Hira': 'ruynguvag5'
62+
},
63+
'switch-costume': {
64+
'en': '1ocp6a1ejn',
65+
'ja': 'g3vluv0ms8',
66+
'ja-Hira': 'g3vluv0ms8'
67+
},
68+
'move-around-with-arrow-keys': {
69+
'en': 'yetrmk4iuu',
70+
'ja': 'fk34dcg5oz',
71+
'ja-Hira': 'fk34dcg5oz'
72+
},
73+
'add-effects': {
74+
'en': '3jvl8zgjo2',
75+
'ja': 'q7zq9vu0wb',
76+
'ja-Hira': 'q7zq9vu0wb'
77+
}
78+
};
79+
80+
/**
81+
* Return a video identifier (on our video hosting service)
82+
* @param {string} videoId key in the videos object, or id string.
83+
* @param {string} locale locale to look up. If locale is not defined return the id for 'en' by default
84+
* @return {string} identifier for the video on our video hosting service.
85+
*/
86+
const translateVideo = (videoId, locale) => {
87+
// if the videoId is not recognized in the videos object, assume it's already a video id on wistia
88+
if (!videos.hasOwnProperty(videoId)) return videoId;
89+
if (videos[videoId].hasOwnProperty(locale)) {
90+
return videos[videoId][locale];
91+
}
92+
return videos[videoId].en;
93+
};
94+
95+
export {
96+
translateVideo
97+
};
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import {translateVideo} from '../../../src/lib/libraries/decks/translate-video.js';
2+
3+
describe('translateVideo', () => {
4+
test('returns the id if it is not found', () => {
5+
expect(translateVideo('not-a-key', 'en')).toEqual('not-a-key');
6+
});
7+
8+
test('returns the expected id for Japanese', () => {
9+
expect(translateVideo('intro-move-sayhello', 'ja')).toEqual('v2c2f3y2sc');
10+
});
11+
12+
test('returns the expected id for English', () => {
13+
expect(translateVideo('intro-move-sayhello', 'en')).toEqual('rpjvs3v9gj');
14+
});
15+
16+
test('returns the English id for non-existent locales', () => {
17+
expect(translateVideo('intro-move-sayhello', 'yum')).toEqual('rpjvs3v9gj');
18+
});
19+
});

0 commit comments

Comments
 (0)