mirror of
https://gitlab.com/PronounsPage/PronounsPage.git
synced 2025-09-24 05:05:20 -04:00
fix(rewrite): Allow for pronoun form variants
This commit is contained in:
parent
e854a89303
commit
33dd2cbb7d
@ -85,6 +85,13 @@ export function isLocaleActive(localeCode: string): boolean {
|
|||||||
return getActiveLocaleDescriptions().some((v) => v.code === localeCode);
|
return getActiveLocaleDescriptions().some((v) => v.code === localeCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface PronounVariant {
|
||||||
|
written: string;
|
||||||
|
pronounced: string;
|
||||||
|
}
|
||||||
|
export interface PronounForm extends PronounVariant {
|
||||||
|
variants?: Array<PronounVariant>;
|
||||||
|
}
|
||||||
export interface Pronoun {
|
export interface Pronoun {
|
||||||
keys: Array<string>;
|
keys: Array<string>;
|
||||||
description?: string;
|
description?: string;
|
||||||
@ -98,7 +105,7 @@ export interface Pronoun {
|
|||||||
thirdForm?: string;
|
thirdForm?: string;
|
||||||
smallForm?: string;
|
smallForm?: string;
|
||||||
|
|
||||||
forms: Record<string, { written: string; pronounced: string }>;
|
forms: Record<string, PronounForm>;
|
||||||
|
|
||||||
canonicalName: string;
|
canonicalName: string;
|
||||||
}
|
}
|
||||||
@ -113,11 +120,37 @@ export function parsePronounFromParts(
|
|||||||
|
|
||||||
const pronounForms: Pronoun["forms"] = {};
|
const pronounForms: Pronoun["forms"] = {};
|
||||||
for (let i = 0; i < forms.length; i++) {
|
for (let i = 0; i < forms.length; i++) {
|
||||||
const form = parts[i].split("|");
|
const [written, pronounced] = parts[i].split("|");
|
||||||
pronounForms[forms[i]] = {
|
|
||||||
written: form[0],
|
const writtenVariants = written.split("&");
|
||||||
pronounced: form[1],
|
const pronouncedVariants = pronounced?.split("&") ?? [];
|
||||||
|
|
||||||
|
const current: PronounForm = {
|
||||||
|
written: writtenVariants.shift()!,
|
||||||
|
pronounced: pronouncedVariants.shift()!,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (writtenVariants.length || pronouncedVariants.length) {
|
||||||
|
const length = Math.max(
|
||||||
|
writtenVariants.length,
|
||||||
|
pronouncedVariants.length
|
||||||
|
);
|
||||||
|
const lastWritten = writtenVariants.length - 1,
|
||||||
|
lastPronounced = pronouncedVariants.length - 1;
|
||||||
|
const variants: PronounForm["variants"] = [];
|
||||||
|
for (let i = 0; i < length; i++) {
|
||||||
|
variants.push({
|
||||||
|
written:
|
||||||
|
writtenVariants[Math.max(i, lastWritten)] ??
|
||||||
|
current.written,
|
||||||
|
pronounced:
|
||||||
|
pronouncedVariants[Math.max(i, lastPronounced)] ??
|
||||||
|
current.pronounced,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
current.variants = variants;
|
||||||
|
}
|
||||||
|
pronounForms[forms[i]] = current;
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@ -341,21 +374,26 @@ export class Locale {
|
|||||||
// I make no guarantee regarding the accuracy.
|
// I make no guarantee regarding the accuracy.
|
||||||
const variants: Set<string> = new Set();
|
const variants: Set<string> = new Set();
|
||||||
|
|
||||||
const firstMorpheme =
|
function allVariants(form: PronounForm): Array<string> {
|
||||||
pronoun.forms[this.morphemes[0]].written.split("&");
|
return [
|
||||||
|
form.written,
|
||||||
|
...(form.variants?.map((v) => v.written) ?? []),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
const firstMorpheme = allVariants(pronoun.forms[this.morphemes[0]]);
|
||||||
if (this.morphemes.length === 1) {
|
if (this.morphemes.length === 1) {
|
||||||
return firstMorpheme;
|
return firstMorpheme;
|
||||||
}
|
}
|
||||||
|
|
||||||
const secondMorpheme =
|
const secondMorpheme = allVariants(pronoun.forms[this.morphemes[1]]);
|
||||||
pronoun.forms[this.morphemes[1]].written.split("&");
|
|
||||||
const thirdMorpheme =
|
const thirdMorpheme =
|
||||||
this.morphemes.length > 2
|
this.morphemes.length > 2
|
||||||
? pronoun.forms[this.morphemes[2]].written.split("&")
|
? allVariants(pronoun.forms[this.morphemes[2]])
|
||||||
: [];
|
: [];
|
||||||
|
|
||||||
let thirdFormMorpheme = pronoun.thirdForm
|
let thirdFormMorpheme = pronoun.thirdForm
|
||||||
? pronoun.forms[pronoun.thirdForm].written.split("&")
|
? allVariants(pronoun.forms[pronoun.thirdForm])
|
||||||
: [];
|
: [];
|
||||||
|
|
||||||
let thirdMorphemeThreeForms = thirdMorpheme;
|
let thirdMorphemeThreeForms = thirdMorpheme;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user