2023-01-16 18:55:00 +09:00
|
|
|
<script setup lang="ts">
|
|
|
|
import type { mastodon } from 'masto'
|
|
|
|
|
|
|
|
const { status } = defineProps<{
|
|
|
|
status: mastodon.v1.Status
|
|
|
|
}>()
|
|
|
|
|
|
|
|
const {
|
|
|
|
toggle: _toggleTranslation,
|
|
|
|
translation,
|
|
|
|
enabled: isTranslationEnabled,
|
2023-01-18 06:41:26 +09:00
|
|
|
} = useTranslation(status, getLanguageCode())
|
2023-01-21 19:19:03 +09:00
|
|
|
const preferenceHideTranslation = usePreferences('hideTranslation')
|
|
|
|
|
2023-01-29 21:18:49 +09:00
|
|
|
const showButton = computed(() => !preferenceHideTranslation.value && isTranslationEnabled)
|
2023-01-16 18:55:00 +09:00
|
|
|
|
|
|
|
let translating = $ref(false)
|
2023-03-31 04:01:24 +09:00
|
|
|
async function toggleTranslation() {
|
2023-01-16 18:55:00 +09:00
|
|
|
translating = true
|
|
|
|
try {
|
|
|
|
await _toggleTranslation()
|
|
|
|
}
|
|
|
|
finally {
|
|
|
|
translating = false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
|
|
|
<div>
|
|
|
|
<button
|
2023-01-21 19:19:03 +09:00
|
|
|
v-if="showButton" p-0 flex="~ center" gap-2 text-sm
|
2023-01-17 03:04:51 +09:00
|
|
|
:disabled="translating" disabled-bg-transparent btn-text class="disabled-text-$c-text-btn-disabled-deeper" @click="toggleTranslation"
|
2023-01-16 18:55:00 +09:00
|
|
|
>
|
|
|
|
<span v-if="translating" block animate-spin preserve-3d>
|
|
|
|
<span block i-ri:loader-2-fill />
|
|
|
|
</span>
|
|
|
|
<div v-else i-ri:translate />
|
|
|
|
{{ translation.visible ? $t('menu.show_untranslated') : $t('menu.translate_post') }}
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<style scoped></style>
|