Skip to content

Commit bb2d39b

Browse files
authored
In voiceover mode, the text is translated into its respective language. (oppia#19762)
* Translate exploration text * fixes frontend coverage * fixes frontend coverage * fixes frontend coverage * fixes frontend coverage * fixes frontend coverage * fixes frontend test * fixes frontend test * fixes frontend test * fixes frontend statement * fixes frontend statement * fixes frontend statement * fixes frontend statement * fixes frontend statement
1 parent 74cc1c3 commit bb2d39b

File tree

3 files changed

+99
-2
lines changed

3 files changed

+99
-2
lines changed

core/templates/pages/exploration-editor-page/translation-tab/state-translation/state-translation.component.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -188,11 +188,11 @@ <h3 tabindex="0">Content</h3>
188188
</span>
189189
</div>
190190
<div class="oppia-editor-card-section" *ngIf="caContent.content._unicode">
191-
<span *ngIf="!caContent.content.unicode" class="oppia-placeholder" tabindex="0">
191+
<span *ngIf="!caContent.content._unicode" class="oppia-placeholder" tabindex="0">
192192
{{ getEmptyContentMessage() }}
193193
</span>
194194
<span>
195-
<p tabindex="0">{{ caContent.content.unicode }}</p>
195+
<p tabindex="0">{{ getRequiredUnicode(caContent.content) }}</p>
196196
</span>
197197
</div>
198198
</div>

core/templates/pages/exploration-editor-page/translation-tab/state-translation/state-translation.component.spec.ts

+71
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ describe('State translation component', () => {
110110
let outcomeObjectFactory: OutcomeObjectFactory;
111111
let stateEditorService: StateEditorService;
112112
let stateRecordedVoiceoversService: StateRecordedVoiceoversService;
113+
let subtitledUnicodeObjectFactory: SubtitledUnicodeObjectFactory;
113114
let translationLanguageService: TranslationLanguageService;
114115
let translationTabActiveContentIdService:
115116
TranslationTabActiveContentIdService;
@@ -314,6 +315,8 @@ describe('State translation component', () => {
314315
explorationStatesService = TestBed.inject(ExplorationStatesService);
315316
stateRecordedVoiceoversService = TestBed.inject(
316317
StateRecordedVoiceoversService);
318+
subtitledUnicodeObjectFactory = TestBed.inject(
319+
SubtitledUnicodeObjectFactory);
317320
translationLanguageService = TestBed.inject(TranslationLanguageService);
318321
translationTabActiveContentIdService = TestBed.inject(
319322
TranslationTabActiveContentIdService);
@@ -605,6 +608,18 @@ describe('State translation component', () => {
605608
'This is the html');
606609
});
607610

611+
it('should get subtitled Unicode data translation', () => {
612+
let subtitledObject = subtitledUnicodeObjectFactory.createFromBackendDict(
613+
{
614+
content_id: 'content_1',
615+
unicode_str: 'This is the unicode'
616+
});
617+
expect(component.getRequiredUnicode(subtitledObject)).toBe(
618+
'This is the unicode');
619+
expect(component.getSubtitledContentSummary(subtitledObject)).toBe(
620+
'This is the unicode');
621+
});
622+
608623
it('should get empty content message when text translations haven\'t' +
609624
' been added yet', () => {
610625
expect(component.getEmptyContentMessage()).toBe(
@@ -1048,6 +1063,7 @@ describe('State translation component', () => {
10481063
let explorationStatesService: ExplorationStatesService;
10491064
let stateEditorService: StateEditorService;
10501065
let stateRecordedVoiceoversService: StateRecordedVoiceoversService;
1066+
let subtitledUnicodeObjectFactory: SubtitledUnicodeObjectFactory;
10511067
let translationLanguageService: TranslationLanguageService;
10521068
let translationTabActiveContentIdService:
10531069
TranslationTabActiveContentIdService;
@@ -1312,6 +1328,8 @@ describe('State translation component', () => {
13121328
explorationStatesService = TestBed.inject(ExplorationStatesService);
13131329
stateRecordedVoiceoversService = TestBed.inject(
13141330
StateRecordedVoiceoversService);
1331+
subtitledUnicodeObjectFactory = TestBed.inject(
1332+
SubtitledUnicodeObjectFactory);
13151333
translationLanguageService = TestBed.inject(TranslationLanguageService);
13161334
translationTabActiveContentIdService = TestBed.inject(
13171335
TranslationTabActiveContentIdService);
@@ -1444,6 +1462,17 @@ describe('State translation component', () => {
14441462
expect(htmlData).toBe('<p>HTML data</p>');
14451463
});
14461464

1465+
it('should return unicode when translation tab is active', () => {
1466+
spyOn(translationTabActiveModeService, 'isTranslationModeActive').and
1467+
.returnValue(true);
1468+
let subtitledObject = subtitledUnicodeObjectFactory.createFromBackendDict({
1469+
content_id: 'content_1',
1470+
unicode_str: 'This is the unicode'
1471+
});
1472+
const unicodeData = component.getRequiredUnicode(subtitledObject);
1473+
expect(unicodeData).toBe('This is the unicode');
1474+
});
1475+
14471476
it('should return translation html when translation available', () => {
14481477
entityTranslationsService.languageCodeToEntityTranslations.en = (
14491478
new EntityTranslation(
@@ -1458,6 +1487,24 @@ describe('State translation component', () => {
14581487
expect(htmlData).toBe('Translated HTML');
14591488
});
14601489

1490+
it('should return unicode when translation is empty in voiceover mode', () =>{
1491+
entityTranslationsService.languageCodeToEntityTranslations.en = (
1492+
new EntityTranslation(
1493+
'entityId', 'entityType', 'entityVersion', 'hi', {
1494+
content_0: new TranslatedContent
1495+
(
1496+
'Translated unicode', 'unicode', true
1497+
)
1498+
})
1499+
);
1500+
let subtitledObject = subtitledUnicodeObjectFactory.createFromBackendDict({
1501+
content_id: 'content_1',
1502+
unicode_str: 'This is the unicode'
1503+
});
1504+
const unicodeData = component.getRequiredUnicode(subtitledObject);
1505+
expect(unicodeData).toBe('This is the unicode');
1506+
});
1507+
14611508
it('should return translation html when translation no available', () => {
14621509
entityTranslationsService.languageCodeToEntityTranslations.en = (
14631510
new EntityTranslation(
@@ -1472,6 +1519,30 @@ describe('State translation component', () => {
14721519
expect(htmlData).toBe('<p>HTML data</p>');
14731520
});
14741521

1522+
it('should return translated unicode in voiceover mode when translation exist'
1523+
, () => {
1524+
entityTranslationsService.languageCodeToEntityTranslations.en = (
1525+
new EntityTranslation(
1526+
'entityId',
1527+
'entityType',
1528+
'entityVersion',
1529+
'hi',
1530+
{
1531+
content_1: new TranslatedContent
1532+
(
1533+
'Translated UNICODE', 'unicode', true
1534+
)
1535+
})
1536+
);
1537+
let subtitledObject = subtitledUnicodeObjectFactory.createFromBackendDict(
1538+
{
1539+
content_id: 'content_1',
1540+
unicode_str: 'This is the unicode'
1541+
});
1542+
const unicodeData = component.getRequiredUnicode(subtitledObject);
1543+
expect(unicodeData).toBe('Translated UNICODE');
1544+
});
1545+
14751546
describe('when rules input tab is accessed but with no rules', () => {
14761547
it('should throw an error when there are no rules', () => {
14771548
spyOn(component, 'isDisabled').and.returnValue(false);

core/templates/pages/exploration-editor-page/translation-tab/state-translation/state-translation.component.ts

+26
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,32 @@ export class StateTranslationComponent
144144
return translationContent.translation as string;
145145
}
146146

147+
getRequiredUnicode(SubtitledUnicode: SubtitledUnicode): string {
148+
if (this.translationTabActiveModeService.isTranslationModeActive()) {
149+
return SubtitledUnicode.unicode;
150+
}
151+
152+
let langCode = this.translationLanguageService.getActiveLanguageCode();
153+
if (
154+
!this.entityTranslationsService
155+
.languageCodeToEntityTranslations.hasOwnProperty(langCode)
156+
) {
157+
return SubtitledUnicode.unicode;
158+
}
159+
160+
let translationContent = (
161+
this.entityTranslationsService
162+
.languageCodeToEntityTranslations[langCode].getWrittenTranslation(
163+
SubtitledUnicode.contentId
164+
)
165+
);
166+
if (!translationContent) {
167+
return SubtitledUnicode.unicode;
168+
}
169+
170+
return translationContent.translation as string;
171+
}
172+
147173
getEmptyContentMessage(): string {
148174
if (this.translationTabActiveModeService.isVoiceoverModeActive()) {
149175
return (

0 commit comments

Comments
 (0)