-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: update globalLocaleRoutes logic
- Loading branch information
Showing
15 changed files
with
187 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<template> | ||
<div> | ||
<h1>Subpage with route param</h1> | ||
<p>{{ useRoute().params.id }}</p> | ||
<NuxtLink to="/"> | ||
Home | ||
</NuxtLink> | ||
|
||
<hr> | ||
|
||
<NuxtLink | ||
id="unlocalized" | ||
:to="$localeRoute({ name: 'unlocalized' })" | ||
> | ||
unlocalized | ||
</NuxtLink> | ||
</div> | ||
</template> | ||
<script setup lang="ts"> | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<template> | ||
<div> | ||
<p id="content"> | ||
{{ $t('page.content') }} | ||
</p> | ||
<p id="locale"> | ||
Current Locale: {{ $getLocale() }} | ||
</p> | ||
|
||
<!-- Display additional info for testing --> | ||
<p id="locales"> | ||
{{ $getLocales().map(locale => locale.code).join(', ') }} | ||
</p> | ||
|
||
<!-- Links for switching locales --> | ||
<div id="locale-links"> | ||
<NuxtLink | ||
id="link-en" | ||
:to="$localeRoute({ name: 'page2' }, 'en')" | ||
> | ||
Switch to English | ||
</NuxtLink> | ||
<NuxtLink | ||
id="link-de" | ||
:to="$localeRoute({ name: 'page2' }, 'de')" | ||
> | ||
Switch to German | ||
</NuxtLink> | ||
</div> | ||
</div> | ||
</template> | ||
|
||
<script setup> | ||
import { useNuxtApp } from '#imports' | ||
const { $t, $getLocale, $getLocales, $tc, $localeRoute } = useNuxtApp() | ||
const customPluralRule = (key, count, _locale, t) => { | ||
const translation = t(key) | ||
if (!translation) { | ||
return null | ||
} | ||
const forms = translation.toString().split('|') | ||
if (count === 0 && forms.length > 2) { | ||
return forms[0].trim() // Case for "no apples" | ||
} | ||
if (count === 1 && forms.length > 1) { | ||
return forms[1].trim() // Case for "one apple" | ||
} | ||
return (forms.length > 2 ? forms[2].trim() : forms[forms.length - 1].trim()).replace('{count}', count.toString()) | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { fileURLToPath } from 'node:url' | ||
import { expect, test } from '@nuxt/test-utils/playwright' | ||
|
||
test.use({ | ||
nuxt: { | ||
rootDir: fileURLToPath(new URL('./fixtures/undefault', import.meta.url)), | ||
}, | ||
// launchOptions: { | ||
// headless: false, // Показывать браузер | ||
// slowMo: 500, // Замедлить выполнение шагов (в миллисекундах) для лучшей видимости | ||
// }, | ||
}) | ||
|
||
// Тест для английского языка | ||
test('test redirection and link clicks in English', async ({ page, goto }) => { | ||
await goto('/', { waitUntil: 'hydration' }) | ||
// Переход на страницу /page2, должно произойти редирект на /en/custom-page2-en | ||
await goto('/page2', { waitUntil: 'hydration' }) | ||
|
||
await expect(page).toHaveURL('/en/custom-page2-en') | ||
|
||
// Клик по ссылке 'unlocalized', должно редиректнуть на /unlocalized | ||
await page.click('#unlocalized') | ||
await expect(page).toHaveURL('/unlocalized') | ||
|
||
// Клик по ссылке 'page2', должно вернуться на /en/custom-page2-en | ||
await page.click('#link-en') | ||
await expect(page).toHaveURL('/en/custom-page2-en') | ||
}) | ||
|
||
// Тест для немецкого языка | ||
test('test redirection and link clicks in German', async ({ page, goto }) => { | ||
await goto('/', { waitUntil: 'hydration' }) | ||
// Переход на страницу /page2, должно произойти редирект на /de/custom-page2-de | ||
await goto('/de/custom-page2-de', { waitUntil: 'hydration' }) | ||
await expect(page).toHaveURL('/de/custom-page2-de') | ||
|
||
// Клик по ссылке 'unlocalized', должно редиректнуть на /unlocalized | ||
await page.click('#unlocalized') | ||
await expect(page).toHaveURL('/unlocalized') | ||
|
||
// Клик по ссылке 'page2', должно вернуться на /en/custom-page2-en | ||
await page.click('#link-de') | ||
await expect(page).toHaveURL('/de/custom-page2-de') | ||
}) |