Merge branch 'german-consider-endings-in-null-pronouns' into 'main'

Use different possessive suffixes depending on the suffix of the name in case of no pronouns

See merge request PronounsPage/PronounsPage!381
This commit is contained in:
Andrea Vos 2023-11-04 15:00:24 +00:00
commit d266859d2a
2 changed files with 19 additions and 2 deletions

View File

@ -22,7 +22,7 @@ pronouns:
pronoun_n: '#'
pronoun_d: '#'
pronoun_a: '#'
possessive: '#s'
possessive: '#/[sxzß]$/i#|#s'
examples: [':Andrea', ':S']
template: 'Öffne eines der Beispiele und ersetze einfach den Namen/Anfangsbuchstaben in der URL durch Deinen eigenen.'
emoji: false

View File

@ -21,6 +21,23 @@ export const getPronoun = (pronouns, id) => {
return addAliasesToPronouns(pronouns)[id];
}
const conditionalKeyPlaceHolder = /#\/([^/]+)\/(\w+)?#/;
const unconditionalKeyPlaceholder = /#/g;
const buildMorphemeFromTemplate = (key, template) => {
const variants = template.split('|');
for (const variant of variants) {
const conditionalMatch = variant.match(conditionalKeyPlaceHolder);
if (conditionalMatch) {
if (key.match(new RegExp(conditionalMatch[1], conditionalMatch[2]))) {
return variant.replace(conditionalKeyPlaceHolder, key);
}
} else {
return variant.replace(unconditionalKeyPlaceholder, key);
}
}
};
const buildPronounFromTemplate = (key, template) => {
return new Pronoun(
key,
@ -29,7 +46,7 @@ const buildPronounFromTemplate = (key, template) => {
buildDict(function*(morphemes) {
for (let k in morphemes) {
if (morphemes.hasOwnProperty(k)) {
yield [k, morphemes[k].replace(/#/g, key)];
yield [k, buildMorphemeFromTemplate(key, morphemes[k])];
}
}
}, template.morphemes),