#71 [bug] fix mixing plurality in templates

This commit is contained in:
Avris 2020-10-12 23:28:26 +02:00
parent af456f4561
commit 99eeedf295
4 changed files with 28 additions and 17 deletions

View File

@ -1,6 +1,6 @@
<template> <template>
<span> <span>
<span v-for="part in example[(example.isHonorific ? template.pluralHonorific : template.plural) ? 'pluralParts' : 'singularParts']"> <span v-for="part in example[(example.isHonorific ? template.isPluralHonorific(counter) : template.isPlural(counter)) ? 'pluralParts' : 'singularParts']">
<strong v-if="part.variable">{{template.getMorpheme(part.str, counter)}}</strong> <strong v-if="part.variable">{{template.getMorpheme(part.str, counter)}}</strong>
<span v-else>{{part.str}}</span> <span v-else>{{part.str}}</span>
</span> </span>

View File

@ -122,7 +122,7 @@
<template v-for="isHonorific in [false, true]"> <template v-for="isHonorific in [false, true]">
<ul> <ul>
<li v-for="example in examples" v-if="example.isHonorific === isHonorific"> <li v-for="example in examples" v-if="example.isHonorific === isHonorific">
<span v-for="part in example[(isHonorific ? selectedTemplate.pluralHonorific : selectedTemplate.plural) ? 'pluralParts' : 'singularParts']"> <span v-for="part in example[(isHonorific ? selectedTemplate.isPluralHonorific() : selectedTemplate.isPlural()) ? 'pluralParts' : 'singularParts']">
<input v-if="part.variable" v-model="selectedTemplate.morphemes[part.str]" <input v-if="part.variable" v-model="selectedTemplate.morphemes[part.str]"
:class="['form-control form-input p-0', {'active': selectedMorpheme === part.str}]" :class="['form-control form-input p-0', {'active': selectedMorpheme === part.str}]"
:size="selectedTemplate.morphemes[part.str] ? selectedTemplate.morphemes[part.str].length : 0" :size="selectedTemplate.morphemes[part.str] ? selectedTemplate.morphemes[part.str].length : 0"
@ -136,11 +136,11 @@
</ul> </ul>
<div class="my-3"> <div class="my-3">
<div class="custom-control custom-switch" v-if="isHonorific"> <div class="custom-control custom-switch" v-if="isHonorific">
<input type="checkbox" class="custom-control-input" id="pluralHonorific" v-model="selectedTemplate.pluralHonorific"> <input type="checkbox" class="custom-control-input" id="pluralHonorific" v-model="selectedTemplate.pluralHonorific[0]">
<label class="custom-control-label" for="pluralHonorific"><T>template.plural</T> <Icon v="level-up"/></label> <label class="custom-control-label" for="pluralHonorific"><T>template.plural</T> <Icon v="level-up"/></label>
</div> </div>
<div class="custom-control custom-switch" v-else> <div class="custom-control custom-switch" v-else>
<input type="checkbox" class="custom-control-input" id="plural" v-model="selectedTemplate.plural"> <input type="checkbox" class="custom-control-input" id="plural" v-model="selectedTemplate.plural[0]">
<label class="custom-control-label" for="plural"><T>template.plural</T> <Icon v="level-up"/></label> <label class="custom-control-label" for="plural"><T>template.plural</T> <Icon v="level-up"/></label>
</div> </div>
</div> </div>

View File

@ -56,8 +56,8 @@ export const parseTemplates = (templatesRaw) => {
yield [morpheme, t[morpheme]]; yield [morpheme, t[morpheme]];
} }
}), }),
t.plural, [t.plural],
t.pluralHonorific, [t.pluralHonorific],
t.sources ? t.sources.split(',') : [], t.sources ? t.sources.split(',') : [],
aliases.slice(1), aliases.slice(1),
t.history, t.history,

View File

@ -147,11 +147,6 @@ export class Template {
} }
merge(other) { merge(other) {
if (this.plural !== other.plural || this.pluralHonorific !== other.pluralHonorific) {
// Cannot mix plurality
return null;
}
return new Template( return new Template(
this.canonicalName + '&' + other.canonicalName, this.canonicalName + '&' + other.canonicalName,
Array.isArray(this.description) ? [...this.description, other.description] : [this.description, other.description], Array.isArray(this.description) ? [...this.description, other.description] : [this.description, other.description],
@ -159,10 +154,11 @@ export class Template {
buildDict(function* (that, other) { buildDict(function* (that, other) {
for (let morpheme of MORPHEMES) { for (let morpheme of MORPHEMES) {
yield [morpheme, (that.morphemes[morpheme] || '') + '&' + (other.morphemes[morpheme] || '')] yield [morpheme, (that.morphemes[morpheme] || '') + '&' + (other.morphemes[morpheme] || '')]
//yield [morpheme, buildMorpheme(that.morphemes[morpheme], that.plural) + '&' + buildMorpheme(other.morphemes[morpheme], other.plural)]
} }
}, this, other), }, this, other),
this.plural, [...this.plural, ...other.plural],
this.pluralHonorific, [...this.pluralHonorific, ...other.pluralHonorific],
); );
} }
@ -176,11 +172,19 @@ export class Template {
return options[counter % options.length] return options[counter % options.length]
} }
isPlural(counter = 0) {
return this.plural[counter % this.plural.length]
}
isPluralHonorific(counter = 0) {
return this.pluralHonorific[counter % this.pluralHonorific.length]
}
toArray() { toArray() {
return [ return [
...Object.values(this.morphemes).map(s => escape(s)), ...Object.values(this.morphemes).map(s => escape(s)),
this.plural ? 1 : 0, this.plural.map(p => p ? 1 : 0).join(''),
this.pluralHonorific ? 1 : 0, this.pluralHonorific.map(p => p ? 1 : 0).join(''),
escape(this.description), escape(this.description),
]; ];
} }
@ -209,7 +213,14 @@ export class Template {
m[MORPHEMES[parseInt(i)]] = data[parseInt(i)]; m[MORPHEMES[parseInt(i)]] = data[parseInt(i)];
} }
return new Template(m[MORPHEMES[0]], data[data.length - 1], false, m, parseInt(data[MORPHEMES.length]) === 1, parseInt(data[MORPHEMES.length + 1]) === 1) return new Template(
m[MORPHEMES[0]],
data[data.length - 1],
false,
m,
data[MORPHEMES.length].split('').map(p => parseInt(p) === 1),
data[MORPHEMES.length + 1].split('').map(p => parseInt(p) === 1),
)
} }
} }
@ -260,7 +271,7 @@ export class TemplateLibrary {
} }
find(template) { find(template) {
if (template === undefined) { if (!template) {
return null; return null;
} }