-
-
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.
- Loading branch information
1 parent
6752118
commit 5cec717
Showing
8 changed files
with
164 additions
and
0 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 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,31 @@ | ||
<script lang="ts" setup> | ||
import { ref, onMounted } from '#imports' | ||
import LangSwitcher from '../components/LangSwitcher.vue' | ||
const products = ref([]) | ||
const { locale } = useI18n() | ||
const localePath = useLocalePath() | ||
onMounted(async () => { | ||
products.value = await $fetch(`/api/products`) | ||
}) | ||
</script> | ||
|
||
<template> | ||
<div> | ||
<LangSwitcher /> | ||
<NuxtLink | ||
class="product" | ||
v-for="product in products" | ||
:key="product.id" | ||
:to="localePath({ name: 'products-slug', params: { slug: product?.slugs?.[locale] ?? 'none' } })" | ||
>{{ product.name?.[locale] }} | ||
</NuxtLink> | ||
<NuxtPage /> | ||
</div> | ||
</template> | ||
|
||
<style> | ||
.product { | ||
padding: 1em 0.5em; | ||
} | ||
</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 @@ | ||
<script lang="ts" setup> | ||
import { useI18n, useLocalePath, useSetI18nParams } from '#i18n' | ||
import { ref, computed, onMounted, useHead, useRoute } from '#imports' | ||
import LangSwitcher from '@/components/LangSwitcher.vue' | ||
const product = ref() | ||
const { locale } = useI18n() | ||
const localePath = useLocalePath() | ||
const route = useRoute() | ||
const head = useHead({}) | ||
const setI18nParams = useSetI18nParams({ addSeoAttributes: true }) | ||
product.value = await $fetch(`/api/products/${route.params.slug}`) | ||
if (product.value != null) { | ||
const availableLocales = Object.keys(product.value.slugs) | ||
const slugs: Record<string, string> = {} | ||
for (const l of availableLocales) { | ||
slugs[l] = { slug: product.value.slugs[l] } | ||
} | ||
setI18nParams(slugs) | ||
} | ||
</script> | ||
|
||
<template> | ||
<div> | ||
<section class="product">{{ product?.name?.[locale] }}</section> | ||
<LangSwitcher /> | ||
</div> | ||
</template> | ||
|
||
<style> | ||
.product { | ||
padding: 1em 0.5em; | ||
} | ||
</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,35 @@ | ||
export default [ | ||
{ | ||
id: 1, | ||
name: { | ||
en: 'Red mug', | ||
nl: 'Rode mok' | ||
}, | ||
slugs: { | ||
en: 'red-mug', | ||
nl: 'rode-mok' | ||
} | ||
}, | ||
{ | ||
id: 2, | ||
name: { | ||
en: 'Big chair', | ||
nl: 'Grote stoel' | ||
}, | ||
slugs: { | ||
en: 'big-chair', | ||
nl: 'grote-stoel' | ||
} | ||
}, | ||
{ | ||
id: 3, | ||
name: { | ||
en: 'Standing desk', | ||
nl: 'Sta bureau' | ||
}, | ||
slugs: { | ||
en: 'standing-desk', | ||
nl: 'sta-bureau' | ||
} | ||
} | ||
] |
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,19 @@ | ||
import type { LocaleMessages, DefineLocaleMessage } from 'vue-i18n' | ||
import productsData from './products-data' | ||
/** | ||
* NOTE: | ||
* locale resources is managed on backend examples | ||
*/ | ||
|
||
const locales: LocaleMessages<DefineLocaleMessage> = { | ||
'en-GB': { | ||
settings: { | ||
profile: 'Profile' | ||
} | ||
}, | ||
ja: {} | ||
} | ||
|
||
export default defineEventHandler(event => { | ||
return productsData | ||
}) |
27 changes: 27 additions & 0 deletions
27
specs/fixtures/basic_usage/server/api/products/[product].ts
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,27 @@ | ||
import type { LocaleMessages, DefineLocaleMessage } from 'vue-i18n' | ||
import productsData from '../products-data' | ||
|
||
/** | ||
* NOTE: | ||
* locale resources is managed on backend examples | ||
*/ | ||
|
||
const locales: LocaleMessages<DefineLocaleMessage> = { | ||
'en-GB': { | ||
settings: { | ||
profile: 'Profile' | ||
} | ||
}, | ||
ja: {} | ||
} | ||
|
||
export default defineEventHandler(event => { | ||
const slug = event.context.params?.product | ||
const found = productsData.find(x => Object.values(x.slugs).includes(slug)) | ||
|
||
if (found == null) { | ||
return {} | ||
} | ||
|
||
return found | ||
}) |