forked from nuxt-modules/i18n
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: cannot redirect when call
setLocale
(nuxt-modules#2307)
* fix: cannot redirect when call setLocale * fix: nuxt-modules#2291 * fix: update lock file
- Loading branch information
Showing
14 changed files
with
687 additions
and
423 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<template> | ||
<div> | ||
<NuxtLayout> | ||
<nav> | ||
<nuxt-link id="root" class="link" to="/"> / </nuxt-link> | ||
<nuxt-link id="root-en" class="link" to="/en"> /en </nuxt-link> | ||
<nuxt-link id="about-en" class="link" to="/en/about"> /en/about </nuxt-link> | ||
<nuxt-link class="link" to="/about"> /about </nuxt-link> | ||
<nuxt-link id="about-ar" class="link" to="/ar/about"> /ar/about </nuxt-link> | ||
<nuxt-link id="example-ar" class="link" to="/ar/example"> /ar/example </nuxt-link> | ||
<nuxt-link id="example-en" class="link" to="/en/example"> /en/example </nuxt-link> | ||
<nuxt-link class="link" to="/example"> /example </nuxt-link> | ||
</nav> | ||
|
||
<br /> | ||
<br /> | ||
<br /><br /> | ||
<div> | ||
Switch language | ||
<button id="ar" @click="switchLanguage('ar')" style="margin-right: 10px">Arabic</button> | ||
<button id="en" @click="switchLanguage('en')">English</button> | ||
</div> | ||
|
||
<br /><br /> | ||
<div> | ||
<strong>Current path: </strong> | ||
<code id="route-path"> | ||
{{ useRoute().path }} | ||
</code> | ||
</div> | ||
|
||
<br /> | ||
<div> | ||
<strong>Current locale: </strong> | ||
<code> | ||
{{ currentLocale }} | ||
</code> | ||
</div> | ||
|
||
<br /><br /><br /><br /> | ||
<NuxtPage /> | ||
</NuxtLayout> | ||
</div> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
const { setLocale, locale } = useI18n() | ||
const currentLocale = computed(() => locale.value) | ||
async function switchLanguage(lang) { | ||
await setLocale(lang) | ||
} | ||
</script> | ||
|
||
<style> | ||
nav { | ||
background-color: #eee; | ||
padding: 10px; | ||
} | ||
.link { | ||
padding: 15px; | ||
} | ||
</style> |
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,3 @@ | ||
export default { | ||
title: 'مرحبا.. هذه اللغة العربية' | ||
} |
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,3 @@ | ||
export default { | ||
title: 'Hello this is English' | ||
} |
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,4 @@ | ||
import ar from './ar-ar' | ||
import en from './en-en' | ||
|
||
export default { ar, en } |
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,5 @@ | ||
<template> | ||
<div> | ||
<slot /> | ||
</div> | ||
</template> |
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,30 @@ | ||
// https://v3.nuxtjs.org/api/configuration/nuxt.config | ||
export default defineNuxtConfig({ | ||
modules: ['@nuxtjs/i18n'], | ||
i18n: { | ||
baseUrl: 'https://abwaab.com', | ||
locales: [ | ||
{ | ||
code: 'en', | ||
country: '', | ||
iso: 'en', | ||
lang: 'en', | ||
file: 'en-en.js', | ||
dir: 'ltr' | ||
}, | ||
{ | ||
code: 'ar', | ||
country: '', | ||
iso: 'ar', | ||
lang: 'ar', | ||
file: 'ar-ar.js', | ||
dir: 'rtl' | ||
} | ||
], | ||
strategy: 'prefix_and_default', | ||
detectBrowserLanguage: false, | ||
defaultLocale: 'ar', | ||
lazy: true, | ||
langDir: 'i18n/' | ||
} | ||
}) |
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,14 @@ | ||
{ | ||
"name": "nuxt3-test-issues-2288", | ||
"private": true, | ||
"scripts": { | ||
"build": "nuxt build", | ||
"dev": "nuxt dev", | ||
"generate": "nuxt generate", | ||
"preview": "nuxt preview" | ||
}, | ||
"devDependencies": { | ||
"@nuxtjs/i18n": "latest", | ||
"nuxt": "latest" | ||
} | ||
} |
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,5 @@ | ||
<template> | ||
<div> | ||
{{ $t('title') }} | ||
</div> | ||
</template> |
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,5 @@ | ||
<template> | ||
<div> | ||
{{ $t('title') }} | ||
</div> | ||
</template> |
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,3 @@ | ||
<template> | ||
<div>Home Page</div> | ||
</template> |
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,41 @@ | ||
import { test, expect, describe } from 'vitest' | ||
import { fileURLToPath } from 'node:url' | ||
import { URL } from 'node:url' | ||
import { setup, url, createPage } from '../utils' | ||
|
||
describe('#2288', async () => { | ||
await setup({ | ||
rootDir: fileURLToPath(new URL(`../fixtures/issues/2288`, import.meta.url)) | ||
}) | ||
|
||
test('change route with setLocale', async () => { | ||
const home = url('/') | ||
const page = await createPage() | ||
await page.goto(home) | ||
|
||
// goto to `/en/about` | ||
await page.locator('#about-en').click() | ||
await page.waitForTimeout(10) | ||
expect(await page.url().endsWith('/en/about')).toBe(true) | ||
|
||
// change to `ar` | ||
await page.locator('#ar').click() | ||
await page.waitForTimeout(10) | ||
expect(await page.url().endsWith('/about')).toBe(true) | ||
|
||
// change to `en` | ||
await page.locator('#en').click() | ||
await page.waitForTimeout(10) | ||
expect(await page.url().endsWith('/en/about')).toBe(true) | ||
|
||
// goto to `/ar/example` | ||
await page.locator('#example-ar').click() | ||
await page.waitForTimeout(10) | ||
expect(await page.url().endsWith('/ar/example')).toBe(true) | ||
|
||
// goto to `/en/example` | ||
await page.locator('#example-en').click() | ||
await page.waitForTimeout(10) | ||
expect(await page.url().endsWith('/en/example')).toBe(true) | ||
}) | ||
}) |
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