Files
blog/frontend/app/components/LanguageSwitch.vue
T
davide 1247a2ca07 Add numbered pagination and redesign the IT/EN language switch
Blog and category archives now show a numbered page list (first, last,
current +/-1, collapsing gaps into an ellipsis) instead of only
previous/next — see shared/utils/pagination.ts's paginationRange().

Renders page links via NuxtLink's custom/v-slot API rather than letting
it render its own <a>: RouterLink's built-in active-class/aria-current
detection compares only the route's path, not its query string, so
every ?page=N link was incorrectly marked as the current page.

The language switch now shows both "Italiano / English" at all times,
with the current one as plain non-interactive text and the other as a
link, moved to the header's top-right corner instead of stacked under
the logo.
2026-09-11 14:31:58 +02:00

72 lines
1.8 KiB
Vue

<script setup lang="ts">
import { STRINGS } from '#shared/utils/i18n'
import { bareLocalePath, localePath } from '#shared/utils/locale'
import type { Locale } from '#shared/utils/locale'
const route = useRoute()
const locale = useLocale()
const langSwitch = useLangSwitchState()
const strings = computed(() => STRINGS[locale.value])
function targetFor(otherLocale: Locale): string {
if (!langSwitch.value.available) return langSwitch.value.fallback
return localePath(otherLocale, bareLocalePath(route.path))
}
</script>
<template>
<div class="lang-switch" :aria-label="strings.langSwitch.ariaLabel" role="group">
<span v-if="locale === 'it'" class="lang-option is-current" aria-current="true">
{{ strings.langSwitch.it }}
</span>
<NuxtLink v-else class="lang-option" :to="targetFor('it')">
{{ strings.langSwitch.it }}
</NuxtLink>
<span class="lang-divider" aria-hidden="true">/</span>
<span v-if="locale === 'en'" class="lang-option is-current" aria-current="true">
{{ strings.langSwitch.en }}
</span>
<NuxtLink v-else class="lang-option" :to="targetFor('en')">
{{ strings.langSwitch.en }}
</NuxtLink>
</div>
</template>
<style scoped>
.lang-switch {
display: inline-flex;
align-items: center;
gap: 0.4rem;
font-size: 0.7rem;
font-weight: 600;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.lang-option {
display: inline-block;
text-decoration: none;
color: var(--color-muted);
padding-block: 0.25rem;
border-bottom: 1px solid transparent;
}
a.lang-option:hover,
a.lang-option:focus-visible {
color: var(--color-ink);
border-bottom-color: var(--color-ink);
}
.lang-option.is-current {
color: var(--color-ink);
border-bottom-color: var(--color-ink);
}
.lang-divider {
color: var(--color-border);
}
</style>