-
-
Notifications
You must be signed in to change notification settings - Fork 492
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed Incorrect locale returned when using different domains (#2383)
* Fixed a bug where the correct locale.code could not be obtained when differentDomains: true and locale.domain is set with a protocol header. * add spec issues 2374 * fix getLocaleDomain * Fixed a bug where the correct locale.code could not be obtained when differentDomains: true and locale.domain is set with a protocol header. * fix: cannot resolve message for jit compilation (#2387) * fix getLocaleDomain --------- Co-authored-by: kazuya kawaguchi <kawakazu80@gmail.com>
- Loading branch information
Showing
8 changed files
with
108 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,5 @@ | ||
<template> | ||
<div> | ||
<NuxtPage /> | ||
</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 @@ | ||
export default { | ||
welcome: 'test issue 2374' | ||
} |
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 { | ||
welcome: '测试问题2374' | ||
} |
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,26 @@ | ||
// https://nuxt.com/docs/api/configuration/nuxt-config | ||
export default defineNuxtConfig({ | ||
modules: ['@nuxtjs/i18n'], | ||
i18n: { | ||
locales: [ | ||
{ | ||
code: 'en', | ||
name: 'English', | ||
iso: 'en', | ||
file: 'en/pc.js', | ||
domain: 'en.nuxt-app.localhost' | ||
}, | ||
{ | ||
code: 'zh-CN', | ||
name: '简体中文', | ||
iso: 'zh', | ||
file: 'zh/pc.js', | ||
domain: 'zh.nuxt-app.localhost' | ||
} | ||
], | ||
differentDomains: true, | ||
detectBrowserLanguage: false, | ||
defaultLocale: 'en', | ||
langDir: 'lang/' | ||
} | ||
}) |
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-2374", | ||
"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,11 @@ | ||
<script lang="ts" setup> | ||
const { t } = useI18n() | ||
</script> | ||
|
||
<template> | ||
<div> | ||
<div id="content">{{ t('welcome') }}</div> | ||
</div> | ||
</template> | ||
|
||
<style scoped></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,36 @@ | ||
import { test, expect, describe } from 'vitest' | ||
import { fileURLToPath } from 'node:url' | ||
import { setup, $fetch } from '../utils' | ||
import { getDom } from '../helper' | ||
|
||
describe('#2374', async () => { | ||
await setup({ | ||
rootDir: fileURLToPath(new URL(`../fixtures/issues/2374`, import.meta.url)) | ||
}) | ||
|
||
describe('detection issues 2374 with host on server', () => { | ||
test.each([ | ||
['en.nuxt-app.localhost', 'test issue 2374'], | ||
['zh.nuxt-app.localhost', '测试问题2374'] | ||
])('%s host', async (host, header) => { | ||
const html = await $fetch('/', { | ||
headers: { | ||
Host: host | ||
} | ||
}) | ||
const dom = getDom(html) | ||
expect(dom.querySelector('#content').textContent).toEqual(header) | ||
}) | ||
}) | ||
|
||
test('detection issues 2374 with x-forwarded-host on server', async () => { | ||
const html = await $fetch('/', { | ||
headers: { | ||
'X-Forwarded-Host': 'zh.nuxt-app.localhost' | ||
} | ||
}) | ||
const dom = getDom(html) | ||
|
||
expect(dom.querySelector('#content').textContent).toEqual('测试问题2374') | ||
}) | ||
}) |
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