-
-
Notifications
You must be signed in to change notification settings - Fork 483
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: not work detectBrowserLanguage on client-side correctly (#2475)
* fix: not work detectBrowserLanguage on client-side correctly * fix
- Loading branch information
Showing
9 changed files
with
110 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<template> | ||
<NuxtPage /> | ||
</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,15 @@ | ||
{ | ||
"Meta": { | ||
"locale": "English" | ||
}, | ||
"Pages": { | ||
"Home": { | ||
"title": "Home page", | ||
"description": "Home page description" | ||
}, | ||
"About": { | ||
"title": "About page", | ||
"description": "About page description" | ||
} | ||
} | ||
} |
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,15 @@ | ||
{ | ||
"Meta": { | ||
"locale": "French" | ||
}, | ||
"Pages": { | ||
"Home": { | ||
"title": "Page d'accueil", | ||
"description": "Page d'accueil description" | ||
}, | ||
"About": { | ||
"title": "À propos", | ||
"description": "A propos description" | ||
} | ||
} | ||
} |
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,22 @@ | ||
import type { LocaleObject } from '#i18n' | ||
|
||
const locales = [ | ||
{ code: 'en', iso: 'en-US', file: 'en-US.json' }, | ||
{ code: 'fr', iso: 'fr-FR', file: 'fr-FR.json' } | ||
] as LocaleObject[] | ||
|
||
const defaultLocale = locales[0] | ||
|
||
export default defineNuxtConfig({ | ||
modules: ['@nuxtjs/i18n'], | ||
i18n: { | ||
locales, | ||
defaultLocale: defaultLocale.code, | ||
langDir: 'locales/', | ||
lazy: true, | ||
strategy: 'no_prefix', | ||
detectBrowserLanguage: { | ||
fallbackLocale: defaultLocale.code | ||
} | ||
} | ||
}) |
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-2473", | ||
"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,6 @@ | ||
<template> | ||
<h1 id="title" v-text="$t('Pages.About.title')" /> | ||
<p v-text="$t('Pages.About.description')" /> | ||
<p v-text="$t('Meta.locale')" /> | ||
<NuxtLinkLocale id="locale" to="/">{{ $t('Pages.Home.title') }}</NuxtLinkLocale> | ||
</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,6 @@ | ||
<template> | ||
<h1 id="title" v-text="$t('Pages.Home.title')" /> | ||
<p v-text="$t('Pages.Home.description')" /> | ||
<p v-text="$t('Meta.locale')" /> | ||
<NuxtLinkLocale id="locale" to="/about">{{ $t('Pages.About.title') }}</NuxtLinkLocale> | ||
</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,28 @@ | ||
import { test, expect, describe } from 'vitest' | ||
import { fileURLToPath } from 'node:url' | ||
import { URL } from 'node:url' | ||
import { setup, url, createPage } from '../utils' | ||
import { getText } from '../helper' | ||
|
||
describe('#2473', async () => { | ||
await setup({ | ||
rootDir: fileURLToPath(new URL(`../fixtures/issues/2473`, import.meta.url)) | ||
}) | ||
|
||
test('should be respected detect browser language', async () => { | ||
const home = url('/') | ||
const page = await createPage(undefined, { locale: 'fr' }) | ||
await page.goto(home) | ||
|
||
expect(await getText(page, '#title')).toEqual(`Page d'accueil`) | ||
|
||
// change page | ||
await page.locator('#locale').click() | ||
await page.waitForURL('**/about') | ||
expect(await getText(page, '#title')).toEqual(`À propos`) | ||
|
||
// one more change page | ||
await page.locator('#locale').click() | ||
expect(await getText(page, '#title')).toEqual(`Page d'accueil`) | ||
}) | ||
}) |
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