-
-
Notifications
You must be signed in to change notification settings - Fork 490
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: layer inline module options not used in generation (#2618)
* fix: layer inline module options not used in generation * test: add regression test for #2617
- Loading branch information
1 parent
64fa2f6
commit 2a7ee97
Showing
11 changed files
with
268 additions
and
5 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
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,79 @@ | ||
<script setup lang="ts"> | ||
import { navigateTo } from '#imports' | ||
import { useLocalePath, useSwitchLocalePath, useLocaleRoute, useI18n } from '#i18n' | ||
const { locale } = useI18n() | ||
const localePath = useLocalePath() | ||
const switchLocalePath = useSwitchLocalePath() | ||
const localeRoute = useLocaleRoute() | ||
const category = ref({ | ||
title: 'Kirby', | ||
slug: 'nintendo' | ||
}) | ||
function onClick() { | ||
const route = localeRoute({ name: 'user-profile', query: { foo: '1' } }) | ||
if (route) { | ||
return navigateTo(route.fullPath) | ||
} | ||
} | ||
</script> | ||
|
||
<template> | ||
<div id="basic-usage-section"> | ||
<h2>Docs Basic usages</h2> | ||
<section id="vue-i18n-usage"> | ||
<h3>vue-i18n</h3> | ||
<div class="vue-i18n"> | ||
<form> | ||
<select v-model="locale"> | ||
<option value="en">en</option> | ||
<option value="fr">fr</option> | ||
</select> | ||
<p>{{ $t('welcome') }}</p> | ||
</form> | ||
</div> | ||
</section> | ||
<section id="locale-path-usages"> | ||
<h3>localePath</h3> | ||
<ul> | ||
<li class="name"> | ||
<NuxtLink :to="localePath('index')">{{ $t('home') }}</NuxtLink> | ||
</li> | ||
<li class="path"> | ||
<NuxtLink :to="localePath('/')">{{ $t('home') }}</NuxtLink> | ||
</li> | ||
<li class="named-with-locale"> | ||
<NuxtLink :to="localePath('index', 'en')">Homepage in English</NuxtLink> | ||
</li> | ||
<li class="nest-path"> | ||
<NuxtLink :to="localePath('/user/profile')">Route by path to: {{ $t('profile') }}</NuxtLink> | ||
</li> | ||
<li class="nest-named"> | ||
<NuxtLink :to="localePath('user-profile')">Route by name to: {{ $t('profile') }}</NuxtLink> | ||
</li> | ||
<li class="object-with-named"> | ||
<NuxtLink :to="localePath({ name: 'category-slug', params: { slug: category.slug } })"> | ||
{{ category.title }} | ||
</NuxtLink> | ||
</li> | ||
</ul> | ||
</section> | ||
<section id="switch-locale-path-usages"> | ||
<h3>switchLocalePath</h3> | ||
<ul> | ||
<li class="switch-to-en"> | ||
<NuxtLink :to="switchLocalePath('en')">English</NuxtLink> | ||
</li> | ||
<li class="switch-to-fr"> | ||
<NuxtLink :to="switchLocalePath('fr')">Français</NuxtLink> | ||
</li> | ||
</ul> | ||
</section> | ||
<section id="locale-route-usages"> | ||
<h3>localeRoute</h3> | ||
<button @click="onClick">Show profile</button> | ||
</section> | ||
</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,40 @@ | ||
<script setup lang="ts"> | ||
import { useI18n, useSwitchLocalePath } from '#i18n' | ||
const { locales, locale, setLocale } = useI18n() | ||
const switchLocalePath = useSwitchLocalePath() | ||
</script> | ||
|
||
<template> | ||
<div> | ||
<section id="lang-switcher-with-nuxt-link"> | ||
<strong>Using <code>NuxtLink</code></strong | ||
>: | ||
<NuxtLink | ||
v-for="(locale, index) in locales" | ||
:key="index" | ||
:exact="true" | ||
:class="`switch-to-${locale.code}`" | ||
:to="switchLocalePath(locale.code)" | ||
>{{ locale.name }}</NuxtLink | ||
> | ||
</section> | ||
<section id="lang-switcher-with-set-locale"> | ||
<strong>Using <code>setLocale()</code></strong | ||
>: | ||
<a | ||
v-for="(locale, index) in locales" | ||
:id="`set-locale-link-${locale.code}`" | ||
:key="`b-${index}`" | ||
href="javascript:void(0)" | ||
@click.prevent="setLocale(locale.code)" | ||
>{{ locale.name }}</a | ||
> | ||
</section> | ||
<section id="lang-switcher-current-locale"> | ||
<strong | ||
>Current Locale: <code>{{ locale }}</code></strong | ||
>: | ||
</section> | ||
</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,6 @@ | ||
{ | ||
"home": "Homepage", | ||
"about": "About us", | ||
"posts": "Posts", | ||
"dynamic": "Dynamic" | ||
} |
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,23 @@ | ||
// https://nuxt.com/docs/guide/directory-structure/nuxt.config | ||
export default defineNuxtConfig({ | ||
modules: [ | ||
[ | ||
'@nuxtjs/i18n', | ||
{ | ||
debug: false, | ||
lazy: false, | ||
langDir: 'lang', | ||
defaultLocale: 'en', | ||
detectBrowserLanguage: false, | ||
locales: [ | ||
{ | ||
code: 'en', | ||
iso: 'en-US', | ||
file: 'locale-file-en.json' | ||
} | ||
] | ||
} | ||
] | ||
], | ||
debug: false | ||
}) |
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-basic-usage-layers", | ||
"private": true, | ||
"type": "module", | ||
"scripts": { | ||
"dev": "nuxi dev", | ||
"build": "nuxt build", | ||
"start": "node .output/server/index.mjs" | ||
}, | ||
"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,3 @@ | ||
<template> | ||
<p>This is cateory page on '{{ $route.params.slug }}'</p> | ||
</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,65 @@ | ||
<script setup lang="ts"> | ||
import { watchEffect } from 'vue' | ||
import { useAsyncData, useHead, useRouter } from '#imports' | ||
import { useI18n, useLocalePath, useLocaleHead } from '#i18n' | ||
import BasicUsage from '../components/BasicUsage.vue' | ||
import LangSwitcher from '../components/LangSwitcher.vue' | ||
const { t } = useI18n() | ||
const localePath = useLocalePath() | ||
const i18nHead = useLocaleHead({ | ||
addDirAttribute: true, | ||
identifierAttribute: 'id', | ||
addSeoAttributes: { canonicalQueries: ['page'] }, | ||
router: useRouter() | ||
}) | ||
const { data, refresh } = useAsyncData('home', () => | ||
Promise.resolve({ | ||
aboutPath: localePath('about'), | ||
aboutTranslation: t('about') | ||
}) | ||
) | ||
watchEffect(() => { | ||
refresh() | ||
}) | ||
useHead({ | ||
title: t('home'), | ||
htmlAttrs: { | ||
lang: i18nHead.value.htmlAttrs!.lang, | ||
dir: i18nHead.value.htmlAttrs!.dir | ||
}, | ||
link: [...(i18nHead.value.link || [])], | ||
meta: [...(i18nHead.value.meta || [])] | ||
}) | ||
</script> | ||
|
||
<template> | ||
<div> | ||
<h1 id="home-header">{{ $t('home') }}</h1> | ||
<!-- <BasicUsage /> --> | ||
<LangSwitcher /> | ||
<section> | ||
<strong>resolve with <code>useAsyncData</code></strong | ||
>: | ||
<code id="home-use-async-data">{{ data }}</code> | ||
</section> | ||
<section> | ||
<strong><code>useHead</code> with <code>useLocaleHead</code></strong | ||
>: | ||
<code id="home-use-locale-head">{{ i18nHead }}</code> | ||
</section> | ||
<section> | ||
<code id="extend-message">{{ t('my-module-exemple.hello') }}</code> | ||
</section> | ||
<NuxtLink id="link-about" exact :to="localePath('about')">{{ $t('about') }}</NuxtLink> | ||
<NuxtLink id="link-blog" :to="localePath('blog')">{{ $t('blog') }}</NuxtLink> | ||
<NuxtLink id="link-ignore-disable" :to="localePath('/ignore-routes/disable')" | ||
>go to ignoring localized disable route</NuxtLink | ||
> | ||
<NuxtLink id="link-ignore-pick" :to="localePath('/ignore-routes/pick')" | ||
>go to ignoring localized pick route</NuxtLink | ||
> | ||
</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> | ||
<p id="profile-page">This is profile page</p> | ||
</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,23 @@ | ||
import { test, expect, describe } from 'vitest' | ||
import { fileURLToPath } from 'node:url' | ||
import { setup } from '../utils' | ||
import { renderPage } from '../helper' | ||
|
||
describe('#2617', async () => { | ||
await setup({ | ||
rootDir: fileURLToPath(new URL(`../fixtures/issues/2617`, import.meta.url)), | ||
browser: true | ||
}) | ||
|
||
test('should use inline locale objects', async () => { | ||
const { consoleLogs } = await renderPage('/') | ||
|
||
expect( | ||
consoleLogs.some( | ||
log => | ||
log.type === 'warning' && | ||
log.text.includes('[vue-i18n-routing] Locale ISO code is required to generate alternate link') | ||
) | ||
).toBe(false) | ||
}) | ||
}) |
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