Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { SFProjectProfile } from 'realtime-server/lib/esm/scriptureforge/models/sf-project';
import { TranslateSource } from 'realtime-server/lib/esm/scriptureforge/models/translate-config';
import language_code_mapping from '../../../../../language_code_mapping.json';
import { hasArrayProp } from '../../../type-utils';
import { SelectableProjectWithLanguageCode } from '../../core/paratext.service';

/** Represents draft sources as a set of two {@link TranslateSource} arrays, and one {@link SFProjectProfile} array. */
Expand Down Expand Up @@ -70,6 +71,16 @@ export function projectToDraftSources(project: SFProjectProfile): DraftSourcesAs
const draftingSources: TranslateSource[] & ({ length: 0 } | { length: 1 }) = [];
const trainingTargets: [SFProjectProfile] = [project];
const draftConfig = project.translateConfig.draftConfig;
// Forward compatibility with the upcoming SF-3163 change to allow draft sources as arrays
if (
hasArrayProp(project.translateConfig.draftConfig, 'trainingSources') &&
hasArrayProp(project.translateConfig.draftConfig, 'draftingSources')
) {
const trainingSources: TranslateSource[] = [...project.translateConfig.draftConfig.trainingSources] as any[];
const draftingSources: TranslateSource[] = [...project.translateConfig.draftConfig.draftingSources] as any[];
const trainingTargets: SFProjectProfile[] = [project];
return { trainingSources, trainingTargets, draftingSources };
}
let trainingSource: TranslateSource | undefined;
if (draftConfig.alternateTrainingSourceEnabled && draftConfig.alternateTrainingSource != null) {
trainingSource = draftConfig.alternateTrainingSource;
Expand Down
4 changes: 4 additions & 0 deletions src/SIL.XForge.Scripture/ClientApp/src/type-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ export function hasProp<X, Y extends PropertyKey>(value: X, property: Y): value
return (isObj(value) || isFn(value)) && property in value;
}

export function hasArrayProp<X, Y extends PropertyKey>(value: X, property: Y): value is X & Record<Y, unknown[]> {
return hasProp(value, property) && Array.isArray(value[property]);
}

export function hasStringProp<X, Y extends PropertyKey>(value: X, property: Y): value is X & Record<Y, string> {
return hasProp(value, property) && typeof value[property] === 'string';
}
Expand Down
Loading