2023-01-16 09:55:00 +00: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-17 21:41:26 +00:00
|
|
|
} = useTranslation(status, getLanguageCode())
|
2023-01-21 10:19:03 +00:00
|
|
|
const preferenceHideTranslation = usePreferences('hideTranslation')
|
|
|
|
|
2023-04-28 07:36:05 +00:00
|
|
|
const showButton = computed(() =>
|
|
|
|
!preferenceHideTranslation.value
|
|
|
|
&& isTranslationEnabled
|
|
|
|
&& status.content.trim().length,
|
|
|
|
)
|
2023-01-16 09:55:00 +00:00
|
|
|
|
2024-02-21 15:20:08 +00:00
|
|
|
const translating = ref(false)
|
2023-03-30 19:01:24 +00:00
|
|
|
async function toggleTranslation() {
|
2024-02-21 15:20:08 +00:00
|
|
|
translating.value = true
|
2023-01-16 09:55:00 +00:00
|
|
|
try {
|
|
|
|
await _toggleTranslation()
|
|
|
|
}
|
|
|
|
finally {
|
2024-02-21 15:20:08 +00:00
|
|
|
translating.value = false
|
2023-01-16 09:55:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
2023-05-04 20:49:12 +00:00
|
|
|
<div v-if="showButton">
|
2023-01-16 09:55:00 +00:00
|
|
|
<button
|
2023-05-04 20:49:12 +00:00
|
|
|
p-0 flex="~ center" gap-2 text-sm
|
2023-01-16 18:04:51 +00:00
|
|
|
:disabled="translating" disabled-bg-transparent btn-text class="disabled-text-$c-text-btn-disabled-deeper" @click="toggleTranslation"
|
2023-01-16 09:55:00 +00: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>
|