Files
blog/frontend/app/components/LanguageSwitch.vue
T

38 lines
942 B
Vue
Raw Normal View History

<script setup lang="ts">
import { STRINGS } from '#shared/utils/i18n'
import { bareLocalePath, localePath } from '#shared/utils/locale'
const route = useRoute()
const locale = useLocale()
const langSwitch = useLangSwitchState()
const target = computed(() => {
if (!langSwitch.value.available) return langSwitch.value.fallback
const otherLocale = locale.value === 'en' ? 'it' : 'en'
return localePath(otherLocale, bareLocalePath(route.path))
})
const label = computed(() => STRINGS[locale.value].langSwitchLabel)
</script>
<template>
<NuxtLink class="lang-switch" :to="target">{{ label }}</NuxtLink>
</template>
<style scoped>
.lang-switch {
display: inline-block;
font-size: 0.75rem;
font-weight: 600;
letter-spacing: 0.14em;
text-transform: uppercase;
text-decoration: none;
padding-block: 0.6rem;
border-bottom: 1px solid transparent;
}
.lang-switch:hover {
border-bottom-color: var(--color-ink);
}
</style>