Skip to content

Commit

Permalink
SF-2986 Add step to confirm language codes before generating draft
Browse files Browse the repository at this point in the history
  • Loading branch information
Nateowami committed Oct 8, 2024
1 parent dcd8db2 commit 07e0404
Show file tree
Hide file tree
Showing 8 changed files with 299 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<h1 class="mat-headline-4">Confirm project setup</h1>
<h2>Training the language model</h2>
<div class="training-data">
<div class="source-description">
<h3>References</h3>
<p>These are in the source language for the translation model.</p>
</div>
<span class="gap"></span>
<div class="target-description">
<h3>Translation project</h3>
<p>These are in the receptor language you are translating into.</p>
</div>
<div class="sources">
@for (project of trainingSources; track project.paratextId) {
<div class="project">
<span class="project-name">{{ project.name }}</span>
<span>
Language code: <strong>{{ project.writingSystem.tag }}</strong>
</span>
</div>
}
</div>
<span class="arrow"><mat-icon>arrow_right_alt</mat-icon></span>
<div class="targets">
@for (project of trainingTargets; track project.paratextId) {
<div class="project">
<span class="project-name">{{ project.name }}</span>
<span>
Language code: <strong>{{ project.writingSystem.tag }}</strong>
</span>
</div>
}
</div>
</div>

<h2>Drafting from</h2>
<p class="translation-data-description">This is the text that will be translated by the language model.</p>
<div class="translation-data">
@for (project of draftingSources; track project.paratextId) {
<div class="project">
<span class="project-name">{{ project.name }}</span>
<span>
Language code: <strong>{{ project.writingSystem.tag }}</strong>
</span>
</div>
}
</div>

<app-notice mode="fill-dark">
<strong>Incorrect language codes will dramatically reduce draft quality.</strong>
<p>Language codes can be changed in Paratext by going to Project Settings > Project Properties > Language.</p>
<mat-checkbox (change)="confirmationChanged($event)">All the language codes are correct.</mat-checkbox>
</app-notice>
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
.training-data {
display: grid;
grid-template-areas: '. . .' '. . .';
row-gap: 1em;
}

.gap,
.arrow {
padding-inline: 2em;
}

.sources,
.targets,
.arrow {
background: #f0f0f0;
display: flex;
flex-direction: column;
justify-content: center;
padding-block: 1em;
gap: 1em;
}

.source-description,
.sources,
.translation-data-description,
.translation-data {
padding-inline-start: 1em;
}

.target-description,
.targets {
padding-inline-end: 1em;
}

.source-description p,
.target-description p,
.translation-data-description {
font-style: italic;
font-size: 0.95em;
}

.training-data h3 {
margin-block: 0 0.5em;
}

.training-data p {
margin: 0;
}

h1,
h2,
h3,
h4,
strong {
font-weight: 500;
}

h1 {
margin-bottom: 0;
}

h2 {
margin-top: 2em;
}

.project {
display: flex;
flex-direction: column;
row-gap: 0.25em;
}

.project-name {
font-size: 1.1em;
font-weight: 500;
}

.translation-data {
margin-bottom: 2.5em;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { Component, EventEmitter, Output } from '@angular/core';
import { MatCheckboxChange, MatCheckboxModule } from '@angular/material/checkbox';
import { MatIconModule } from '@angular/material/icon';
import { TranslocoModule } from '@ngneat/transloco';
import { SFProjectProfile } from 'realtime-server/lib/esm/scriptureforge/models/sf-project';
import { TranslateSource } from 'realtime-server/lib/esm/scriptureforge/models/translate-config';
import { ActivatedProjectService } from '../../../../xforge-common/activated-project.service';
import { NoticeComponent } from '../../../shared/notice/notice.component';

@Component({
selector: 'app-confirm-sources',
standalone: true,
imports: [TranslocoModule, NoticeComponent, MatCheckboxModule, MatIconModule],
templateUrl: './confirm-sources.component.html',
styleUrl: './confirm-sources.component.scss'
})
export class ConfirmSourcesComponent {
@Output() languageCodesVerified = new EventEmitter<boolean>(false);

trainingSources: TranslateSource[] = [];
trainingTargets: SFProjectProfile[] = [];
draftingSources: TranslateSource[] = [];

constructor(activatedProjectService: ActivatedProjectService) {
const project = activatedProjectService.projectDoc!.data!;
this.trainingTargets.push(project);

let trainingSource: TranslateSource | undefined;
if (project.translateConfig.draftConfig.alternateTrainingSourceEnabled) {
trainingSource = project.translateConfig.draftConfig.alternateTrainingSource;
} else {
trainingSource = project.translateConfig.source;
}

if (trainingSource != null) {
this.trainingSources.push(trainingSource);
}

if (project.translateConfig.draftConfig.additionalTrainingSourceEnabled) {
this.trainingSources.push(project.translateConfig.draftConfig.additionalTrainingSource!);
}

let draftingSource: TranslateSource | undefined;
if (project.translateConfig.draftConfig.alternateSourceEnabled) {
draftingSource = project.translateConfig.draftConfig.alternateSource;
} else {
draftingSource = project.translateConfig.source;
}

if (draftingSource != null) {
this.draftingSources.push(draftingSource);
}
}

confirmationChanged(change: MatCheckboxChange): void {
this.languageCodesVerified.emit(change.checked);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import { CommonModule } from '@angular/common';
import { TranslocoModule } from '@ngneat/transloco';
import { Meta, moduleMetadata, StoryObj } from '@storybook/angular';
// import { I18nStoryModule } from '../../../../xforge-common/i18n-story.module';
// import { UICommonModule } from '../../../../xforge-common/ui-common.module';
import { createTestProjectProfile } from 'realtime-server/lib/esm/scriptureforge/models/sf-project-test-data';
import { instance, mock, when } from 'ts-mockito';
import { ActivatedProjectService } from '../../../../xforge-common/activated-project.service';
import { SFProjectProfileDoc } from '../../../core/models/sf-project-profile-doc';
import { ConfirmSourcesComponent } from './confirm-sources.component';

const mockedActivatedProjectService = mock(ActivatedProjectService);

when(mockedActivatedProjectService.projectDoc).thenReturn({
data: createTestProjectProfile({
name: 'Test Project',
translateConfig: {
source: {
projectRef: 'source-project',
shortName: 'SP',
name: 'THIS PROJECT SHOULD NOT BE SHOWN!!!!!****',
paratextId: 'source-project',
writingSystem: { tag: 'es' }
},
draftConfig: {
alternateTrainingSourceEnabled: true,
alternateTrainingSource: {
projectRef: 'alternate-training-source',
shortName: 'ATS',
name: 'Alternate Training Source',
paratextId: 'alternate-training-source',
writingSystem: { tag: 'es' }
},
additionalTrainingSourceEnabled: true,
additionalTrainingSource: {
projectRef: 'additional-training-source',
shortName: 'ATS',
name: 'Additional Training Source',
paratextId: 'additional-training-source',
writingSystem: { tag: 'es' }
},
alternateSourceEnabled: true,
alternateSource: {
projectRef: 'alternate-drafting-source',
shortName: 'ADS',
name: 'Alternate Drafting Source',
paratextId: 'alternate-drafting-source',
writingSystem: { tag: 'es' }
}
}
}
})
} as SFProjectProfileDoc);

const meta: Meta = {
title: 'Translate/ConfirmSources',
component: ConfirmSourcesComponent,
decorators: [
moduleMetadata({
imports: [CommonModule, TranslocoModule],
providers: [{ provide: ActivatedProjectService, useValue: instance(mockedActivatedProjectService) }]
})
]
};

export default meta;

interface StoryState {}

type Story = StoryObj<StoryState>;

export const Default: Story = {
args: {
book: 1,
progress: 0.37,
hues: [0]
}
};
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
<ng-container *transloco="let t; read: 'draft_generation_steps'">
@if (availableTranslateBooks && availableTranslateBooks.length > 0) {
<mat-stepper orientation="vertical" linear (selectionChange)="onStepChange()">
<mat-stepper orientation="horizontal" linear (selectionChange)="onStepChange()">
<mat-step [completed]="languagesVerified">
<ng-template matStepLabel> Confirm setup</ng-template>
<app-confirm-sources (languageCodesVerified)="languagesVerified = $event"></app-confirm-sources>
@if (nextClickedOnLanguageVerification && !languagesVerified) {
<app-notice type="error" mode="fill-dark">
Please confirm the language codes are correct before continuing.
</app-notice>
}
<div class="button-strip">
<button mat-flat-button (click)="nextClickedOnLanguageVerification = true; tryAdvanceStep()" color="primary">
{{ t("next") }}
</button>
</div>
</mat-step>
<mat-step [completed]="userSelectedTranslateBooks.length > 0">
<ng-template matStepLabel>
{{ t("choose_books_to_translate") }}
Expand Down Expand Up @@ -36,9 +50,8 @@ <h4>
</app-notice>
}
<div class="button-strip">
<button mat-flat-button (click)="tryAdvanceStep()" color="primary">
{{ t("next") }}
</button>
<button mat-stroked-button matStepperPrevious>{{ t("back") }}</button>
<button mat-flat-button (click)="tryAdvanceStep()" color="primary">{{ t("next") }}</button>
</div>
</mat-step>
<mat-step [completed]="isTrainingOptional || userSelectedTrainingBooks.length > 0">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
:host {
display: block;
max-width: 80em;
}

.stepper-multi-header {
h2,
h3 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { BookMultiSelectComponent } from '../../../shared/book-multi-select/book
import { ProgressService } from '../../../shared/progress-service/progress.service';
import { SharedModule } from '../../../shared/shared.module';
import { NllbLanguageService } from '../../nllb-language.service';
import { ConfirmSourcesComponent } from '../confirm-sources/confirm-sources.component';
import { DraftSource, DraftSourcesService } from '../draft-sources.service';
import { TrainingDataMultiSelectComponent } from '../training-data/training-data-multi-select.component';
import { TrainingDataUploadDialogComponent } from '../training-data/training-data-upload-dialog.component';
Expand All @@ -43,13 +44,17 @@ export interface DraftGenerationStepsResult {
TranslocoMarkupModule,
BookMultiSelectComponent,
TrainingDataMultiSelectComponent,
TrainingDataUploadDialogComponent
TrainingDataUploadDialogComponent,
ConfirmSourcesComponent
]
})
export class DraftGenerationStepsComponent extends SubscriptionDisposable implements OnInit {
@Output() done = new EventEmitter<DraftGenerationStepsResult>();
@ViewChild(MatStepper) stepper!: MatStepper;

languagesVerified = false;
nextClickedOnLanguageVerification = false;

availableTranslateBooks?: number[] = undefined;
availableTrainingBooks: number[] = [];
availableTrainingData: Readonly<TrainingData>[] = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import { ServalProjectComponent } from '../../serval-administration/serval-proje
import { SharedModule } from '../../shared/shared.module';
import { WorkingAnimatedIndicatorComponent } from '../../shared/working-animated-indicator/working-animated-indicator.component';
import { NllbLanguageService } from '../nllb-language.service';
import { ConfirmSourcesComponent } from './confirm-sources/confirm-sources.component';
import { BuildConfig, DraftZipProgress, activeBuildStates } from './draft-generation';
import {
DraftGenerationStepsComponent,
Expand Down Expand Up @@ -61,7 +62,8 @@ import { SupportedBackTranslationLanguagesDialogComponent } from './supported-ba
DraftInformationComponent,
SupportedBackTranslationLanguagesDialogComponent,
ServalProjectComponent,
DraftPreviewBooksComponent
DraftPreviewBooksComponent,
ConfirmSourcesComponent
]
})
export class DraftGenerationComponent extends DataLoadingComponent implements OnInit {
Expand Down

0 comments on commit 07e0404

Please sign in to comment.