This repository has been archived on 2024-07-22. You can view files and clone it, but cannot push or open issues or pull requests.
Zaimki/components/Example.vue

71 lines
2.7 KiB
Vue
Raw Normal View History

2020-09-13 13:15:44 -07:00
<template>
<span>
<span v-for="part in example[(example.isHonorific ? pronoun.isPluralHonorific(counter) : pronoun.isPlural(counter)) ? 'pluralParts' : 'singularParts']">
2021-03-06 10:54:40 -08:00
<strong v-if="part.variable"><Spelling :text="pronoun.getMorpheme(part.str, counter)"/></strong>
2021-02-01 12:03:30 -08:00
<span v-else><Spelling>{{part.str}}</Spelling></span>
2020-09-13 13:15:44 -07:00
</span>
<small v-if="link">
2021-02-01 12:03:30 -08:00
(<nuxt-link :to="'/' + pronoun.canonicalName"><Spelling>{{ pronoun.canonicalName }}</Spelling></nuxt-link>)
2020-09-13 13:15:44 -07:00
</small>
<template v-if="config.pronunciation.enabled && pronounce && pronoun.pronounceable && example.pronounce(pronoun)">
<a v-for="(link, name) in pronunciationLinks"
class="mr-2"
:href="link"
@click.prevent="pronounce(link)">
<Icon v="volume"/><sub v-if="name">{{name}}</sub>
</a>
</template>
2020-09-13 13:15:44 -07:00
</span>
</template>
<script>
2020-11-28 07:52:48 -08:00
import { pronouns } from "~/src/data";
2020-09-13 13:15:44 -07:00
export default {
props: {
example: { required: true },
pronoun: { required: true },
2020-09-13 13:15:44 -07:00
counter: { default: 0 },
link: { type: Boolean },
2020-11-28 07:52:48 -08:00
pronunciation: { type: Boolean },
},
methods: {
pronounce(link) {
const sound = new Audio(link);
2020-11-28 07:52:48 -08:00
sound.play();
}
},
computed: {
pronounBase() {
const name = this.pronoun.name();
for (let key in pronouns) {
if (!pronouns.hasOwnProperty(key)) { continue; }
if (key === name) {
return key;
}
for (let alias of pronouns[key].aliases) {
if (alias === name) {
return key;
}
}
}
return null;
},
pronounToString() {
return this.pronounBase && pronouns[this.pronounBase].equals(this.pronoun) ? this.pronounBase : this.pronoun.toString();
},
pronunciationLinks() {
const justOne = Object.keys(this.config.pronunciation.voices).length === 1;
const links = {};
for (let country in this.config.pronunciation.voices) {
if (!this.config.pronunciation.voices.hasOwnProperty(country)) { continue; }
links[justOne ? '' : country] = `/api/pronounce/${country}/${this.pronounToString}?example=${encodeURIComponent(this.example.toString())}`;
}
return links;
2020-11-28 07:52:48 -08:00
}
2020-09-13 13:15:44 -07:00
}
}
</script>