Skip to content

Commit 40b9d56

Browse files
fix: remove url localization
Co-authored-by: Luis Emidio <luisfuturist@gmail.com>
1 parent f44947b commit 40b9d56

File tree

20 files changed

+22
-57
lines changed

20 files changed

+22
-57
lines changed

app/components/framework/A.vue

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,21 @@
11
<script setup lang="ts">
2-
import { localizeUrl } from '@psitta/core'
3-
import { useLocale } from '@psitta/vue'
4-
52
interface Props {
63
activeClass?: string
74
href?: string
5+
// Localize is not used anymore, but kept for compatibility.
86
localize?: boolean | undefined
97
locale?: string
108
}
119
12-
const props = withDefaults(defineProps<Props>(), {
10+
withDefaults(defineProps<Props>(), {
1311
localize: undefined,
1412
})
15-
16-
const locale = useLocale()
17-
18-
const normalHref = computed(() => {
19-
return props.localize ?? true
20-
? localizeUrl(props.href, props.locale || locale.value)
21-
: props.href
22-
})
2313
</script>
2414

2515
<template>
2616
<NuxtLink
2717
:active-class="activeClass || 'is-active'"
28-
:to="normalHref"
18+
:to="href"
2919
>
3020
<slot />
3121
</NuxtLink>

app/middleware/psitta.global.ts

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,21 @@
1-
import { detectLocaleFromAcceptLanguage, detectLocaleFromCookie, detectLocaleFromNavigator, detectLocaleFromPathname, getConfig } from '@psitta/core'
2-
import type { RouteLocationNormalized } from 'vue-router'
1+
import { detectLocaleFromAcceptLanguage, detectLocaleFromCookie, detectLocaleFromNavigator, getConfig } from '@psitta/core'
32

4-
export default defineNuxtRouteMiddleware((to: RouteLocationNormalized) => {
3+
export default defineNuxtRouteMiddleware(() => {
54
const { defaultLocale } = getConfig()
6-
const pathname = to.fullPath
75

8-
const { urlWithoutLocale, locale } = detectLocaleFromPathname(pathname)
6+
const cookie = useCookie('locale')
97

10-
if (!locale) {
11-
const cookie = useCookie('locale').value
12-
13-
let locale = detectLocaleFromCookie(cookie || undefined)
8+
let locale = detectLocaleFromCookie(cookie.value || undefined)
149

15-
if (!locale) {
16-
// eslint-disable-next-line nuxt/prefer-import-meta, node/prefer-global/process
17-
const acceptLanguage = process.server ? null : detectLocaleFromNavigator()?.language
18-
19-
const header = useRequestHeader('accept-language')
20-
locale = header
21-
? detectLocaleFromAcceptLanguage(header)?.language || defaultLocale
22-
: acceptLanguage || defaultLocale
23-
}
10+
if (!locale) {
11+
// eslint-disable-next-line nuxt/prefer-import-meta, node/prefer-global/process
12+
const acceptLanguage = process.server ? null : detectLocaleFromNavigator()?.language
2413

25-
if (locale !== defaultLocale && pathname === urlWithoutLocale) {
26-
if (pathname.startsWith('/api/'))
27-
return
14+
const header = useRequestHeader('accept-language')
15+
locale = header
16+
? detectLocaleFromAcceptLanguage(header)?.language || defaultLocale
17+
: acceptLanguage || defaultLocale
2818

29-
return navigateTo(`/${locale}${urlWithoutLocale}`, { replace: true })
30-
}
19+
cookie.value = locale
3120
}
3221
})

app/modals/LocaleModal.vue

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<script setup lang="ts">
2+
import { getConfig } from '@psitta/core'
23
import { useForm } from 'vee-validate'
3-
import { detectLocaleFromPathname, getConfig } from '@psitta/core'
44
import { LOCALES } from '~/constants/base'
55
66
const { defaultLocale } = getConfig()
@@ -18,26 +18,17 @@ onMounted(() => {
1818
const isOpen = defineModel({ default: false })
1919
const loading = ref(false)
2020
21-
const route = useRoute()
22-
23-
const { urlWithoutLocale } = detectLocaleFromPathname(route.path)
24-
2521
const submit = form.handleSubmit(async (data) => {
2622
const locale = data.locale
2723
28-
const localeCookie = useCookie('locale', { path: '/' })
24+
const localeCookie = useCookie('locale')
2925
localeCookie.value = locale
3026
3127
loading.value = true
3228
3329
const scrollX = window.scrollX
3430
const scrollY = window.scrollY
3531
36-
if (locale === defaultLocale)
37-
await navigateTo(urlWithoutLocale, { replace: true })
38-
else
39-
await navigateTo(`/${locale}${urlWithoutLocale}`, { replace: true })
40-
4132
requestAnimationFrame(() => {
4233
setTimeout(() => {
4334
window.scrollTo(scrollX, scrollY)
File renamed without changes.
File renamed without changes.
Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,11 @@
11
<script setup lang="ts">
2-
import { getConfig } from '@psitta/core'
32
import { T, t, useLocale } from '@psitta/vue'
43
import { AccordionRoot } from 'reka-ui'
54
import { SubscriptionStatus } from '~~/db/schema'
65
76
definePageMeta({
87
layout: 'site',
98
layoutTransition: false,
10-
validate(route) {
11-
if (!route.params.locale)
12-
return true
13-
return getConfig().locales.includes(route.params.locale as string)
14-
},
159
})
1610
1711
useAutoRedirect()
File renamed without changes.

0 commit comments

Comments
 (0)