#71 [bug] fix mixing plurality in templates
This commit is contained in:
parent
af456f4561
commit
99eeedf295
|
@ -1,6 +1,6 @@
|
|||
<template>
|
||||
<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>
|
||||
<span v-else>{{part.str}}</span>
|
||||
</span>
|
||||
|
|
|
@ -122,7 +122,7 @@
|
|||
<template v-for="isHonorific in [false, true]">
|
||||
<ul>
|
||||
<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]"
|
||||
:class="['form-control form-input p-0', {'active': selectedMorpheme === part.str}]"
|
||||
:size="selectedTemplate.morphemes[part.str] ? selectedTemplate.morphemes[part.str].length : 0"
|
||||
|
@ -136,11 +136,11 @@
|
|||
</ul>
|
||||
<div class="my-3">
|
||||
<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>
|
||||
</div>
|
||||
<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>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -56,8 +56,8 @@ export const parseTemplates = (templatesRaw) => {
|
|||
yield [morpheme, t[morpheme]];
|
||||
}
|
||||
}),
|
||||
t.plural,
|
||||
t.pluralHonorific,
|
||||
[t.plural],
|
||||
[t.pluralHonorific],
|
||||
t.sources ? t.sources.split(',') : [],
|
||||
aliases.slice(1),
|
||||
t.history,
|
||||
|
|
|
@ -147,11 +147,6 @@ export class Template {
|
|||
}
|
||||
|
||||
merge(other) {
|
||||
if (this.plural !== other.plural || this.pluralHonorific !== other.pluralHonorific) {
|
||||
// Cannot mix plurality
|
||||
return null;
|
||||
}
|
||||
|
||||
return new Template(
|
||||
this.canonicalName + '&' + other.canonicalName,
|
||||
Array.isArray(this.description) ? [...this.description, other.description] : [this.description, other.description],
|
||||
|
@ -159,10 +154,11 @@ export class Template {
|
|||
buildDict(function* (that, other) {
|
||||
for (let morpheme of MORPHEMES) {
|
||||
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.plural,
|
||||
this.pluralHonorific,
|
||||
[...this.plural, ...other.plural],
|
||||
[...this.pluralHonorific, ...other.pluralHonorific],
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -176,11 +172,19 @@ export class Template {
|
|||
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() {
|
||||
return [
|
||||
...Object.values(this.morphemes).map(s => escape(s)),
|
||||
this.plural ? 1 : 0,
|
||||
this.pluralHonorific ? 1 : 0,
|
||||
this.plural.map(p => p ? 1 : 0).join(''),
|
||||
this.pluralHonorific.map(p => p ? 1 : 0).join(''),
|
||||
escape(this.description),
|
||||
];
|
||||
}
|
||||
|
@ -209,7 +213,14 @@ export class Template {
|
|||
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) {
|
||||
if (template === undefined) {
|
||||
if (!template) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
Reference in New Issue