(nouns) make noun template variants optional

This commit is contained in:
Valentyne Stigloher 2024-11-14 13:03:40 +01:00
parent b918be44a5
commit 7b7841e09b
2 changed files with 14 additions and 15 deletions

View File

@ -1,3 +1,5 @@
import type { gendersWithNumerus } from '~/src/classes.ts';
export type PronounData<M extends string> = {
key: string;
description: string;
@ -26,11 +28,6 @@ export interface PronounExamplesData {
isHonorific?: boolean;
}
export interface NounTemplatesData {
masc: string;
fem: string;
neutr: string;
mascPl: string;
femPl: string;
neutrPl: string;
}
export type NounTemplatesData = {
[G in typeof gendersWithNumerus[number]]?: string;
};

View File

@ -4,6 +4,8 @@ import type { Config } from '../locale/config.ts';
import { buildDict, buildList, capitalise, escapeControlSymbols, escapePronunciationString } from './helpers.ts';
import type { Translator } from './translator.ts';
import type { NounTemplatesData } from '~/locale/data.ts';
export class ExamplePart {
variable: boolean;
str: string;
@ -1031,14 +1033,14 @@ export class NounTemplate {
this.neutrPl = neutrPl;
}
static from(data: Record<typeof gendersWithNumerus[number], string>): NounTemplate {
static from(data: NounTemplatesData): NounTemplate {
return new NounTemplate(
data.masc.split('/'),
data.fem.split('/'),
data.neutr.split('/'),
data.mascPl.split('/'),
data.femPl.split('/'),
data.neutrPl.split('/'),
data.masc?.split('/') ?? [],
data.fem?.split('/') ?? [],
data.neutr?.split('/') ?? [],
data.mascPl?.split('/') ?? [],
data.femPl?.split('/') ?? [],
data.neutrPl?.split('/') ?? [],
);
}