Skip to content

Commit

Permalink
chore: playground restructure (#3173)
Browse files Browse the repository at this point in the history
  • Loading branch information
BobbieGoede authored Oct 10, 2024
1 parent 433492f commit beb8e58
Show file tree
Hide file tree
Showing 40 changed files with 175 additions and 297 deletions.
9 changes: 9 additions & 0 deletions playground/app.vue → playground/app/app.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,19 @@
</template>

<style>
:root {
font-family: Arial, Helvetica, sans-serif;
}
html {
padding: 0.5em;
}
.my-enter-active,
.my-leave-active {
transition: opacity 0.3s;
}
.my-enter,
.my-leave-active {
opacity: 0;
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import { useLocaleHead } from '#i18n'
const route = useRoute()
const { t } = useI18n()
const head = useLocaleHead({ addLangAttribute: true, addDirAttribute: true, addSeoAttributes: true })
const title = computed(() => t('layouts.title', { title: t(route.meta.title ?? 'TBD') }))
const head = useLocaleHead()
const title = computed(() => t('layouts.title', { title: t(String(route.meta.title ?? 'TBD')) }))
</script>

<template>
<div>
<Html :lang="head.htmlAttrs.lang">
<Html :lang="head.htmlAttrs!.lang">
<Head>
<Title>{{ title }}</Title>
<template v-for="link in head.link" :key="link.hid">
Expand All @@ -19,12 +19,17 @@ const title = computed(() => t('layouts.title', { title: t(route.meta.title ?? '
<Meta :id="meta.hid" :property="meta.property" :content="meta.content" />
</template>
</Head>

<Body>
<slot />
<div>
<h2>I18n Head</h2>
<pre>{{ head }}</pre>
</div>

<section>
<h3>Head</h3>
<details>
<summary>Show head tags</summary>
<pre>{{ head }}</pre>
</details>
</section>
</Body>
</Html>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export default defineNuxtModule<ModuleOptions>({
langDir: resolver.resolve('./lang'),
locales: [
{
name: 'Deutsch',
code: 'de',
language: 'de-DE',
file: 'de.ts'
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export default defineComponent({
<template>
<div>
<nav>
<NuxtLink :to="$localePath('/')">Back to Home</NuxtLink>
<NuxtLink :to="$localePath('index')">Back to Home</NuxtLink>
</nav>
<nav>
<span v-for="locale in availableLocales" :key="locale.code">
Expand All @@ -54,6 +54,6 @@ export default defineComponent({
</span>
</nav>
<p>{{ switchableLocale }}</p>
<p>{{ $localeHead({ addSeoAttributes: true }) }}</p>
<p>{{ $localeHead({}) }}</p>
</div>
</template>
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ defineI18nRoute({
const { t, locales, baseUrl } = useI18n({
useScope: 'local'
})
console.log('locales', locales, baseUrl)
</script>

<template>
Expand Down
File renamed without changes.
125 changes: 125 additions & 0 deletions playground/app/pages/index.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
<script setup lang="ts">
import { computed } from 'vue'
const { t, rt, tm, strategy, locale, locales, setLocale } = useI18n()
const localePath = useLocalePath()
const switchLocalePath = useSwitchLocalePath()
function getLocaleName(code: string) {
const locale = locales.value.find(i => i.code === code)
return locale ? locale.name : code
}
const availableLocales = computed(() => {
return locales.value.filter(i => i.code !== locale.value)
})
const i = tm('items') || []
const items = i.map(item => rt(item?.name ?? ''))
definePageMeta({
title: 'pages.title.top',
pageTransition: {
name: 'page',
mode: 'out-in',
onBeforeEnter: async () => {
const { finalizePendingLocaleChange } = useNuxtApp().$i18n
await finalizePendingLocaleChange()
}
}
})
</script>

<template>
<div>
<h1>Demo: Nuxt 3</h1>
<section>
<p>Current Language: {{ getLocaleName(locale) }}</p>
<p>Current Strategy: {{ strategy }}</p>
</section>
<section>
<h3 class="margin-bottom: 0;">Language switchers</h3>
<div style="display: flex; column-gap: 1em">
<div>
<span>`switchLocalePath` switcher</span>
<ul>
<li v-for="locale in availableLocales" :key="locale.code">
<NuxtLink :to="switchLocalePath(locale.code) || ''">{{ locale.name }}</NuxtLink>
</li>
</ul>
</div>
<div>
<span>`setLocale` switcher</span>
<ul>
<li v-for="locale in availableLocales" :key="locale.code">
<a href="javascript:void(0)" @click="setLocale(locale.code)">{{ locale.name }}</a>
</li>
</ul>
</div>
</div>
</section>
<section>
<h3>Pages</h3>
<ul>
<li>
<NuxtLink :to="localePath('index')">Home</NuxtLink>
</li>
<li>
<NuxtLink :to="localePath({ name: 'about' })">About</NuxtLink>
</li>
<li>
<NuxtLink :to="localePath({ name: 'blog' })">Blog</NuxtLink>
</li>
<li>
<NuxtLink :to="localePath({ name: 'server' })">Server</NuxtLink>
</li>
<li>
<NuxtLink :to="localePath({ name: 'category-id', params: { id: 'foo' } })">Category</NuxtLink>
</li>
<li>
<NuxtLinkLocale :to="{ name: 'history' }" class="history-link">History</NuxtLinkLocale>
</li>
<li>
<NuxtLinkLocale to="index" locale="ja" activeClass="link-active">Home (Japanese)</NuxtLinkLocale>
</li>
<li>
<NuxtLinkLocale :to="{ name: 'products' }" class="products-link">Products</NuxtLinkLocale>
</li>
</ul>
</section>
<section>
<h3>Translations</h3>
<p>{{ $t('hello', { name: 'nuxt3' }) }}</p>
<p>{{ $t('snakeCaseText') }}</p>
<p>{{ $t('pascalCaseText') }}</p>
<p>{{ $t('bar.buz', { name: 'buz' }) }}</p>
<p>{{ $t('settings.profile', {}, { locale: 'en' }) }}</p>
<p>{{ $t('tag') }}</p>
<div>v-t directive: <code v-t="{ path: 'hello', args: { name: 'v-t' } }"></code></div>
<p>Items</p>
<ul>
<li v-for="item in items">{{ item }}</li>
</ul>
</section>
</div>
</template>

<style scoped>
section {
margin: 2em 0em;
}
.page-enter-active,
.page-leave-active {
transition: opacity 0.5s ease;
}
.page-enter-from,
.page-leave-to {
opacity: 0;
}
.link-active {
color: rgb(51, 175, 51);
}
</style>
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
22 changes: 0 additions & 22 deletions playground/i18n.config.ts

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
20 changes: 0 additions & 20 deletions playground/layers/i18n-layer/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,26 +36,6 @@ export default defineNuxtConfig({
// domain: 'localhost',
name: 'Nederlands'
}
// {
// code: 'en-GB',
// language: 'en-GB',
// files: ['en.json', 'en-GB.json'],
// name: 'English (UK)'
// },
// {
// code: 'ja',
// language: 'ja-JP',
// file: 'ja.json',
// domain: 'mydomain.com',
// name: 'Japanses'
// },
// {
// code: 'fr',
// language: 'fr-FR',
// file: 'fr.json',
// domain: 'mydomain.fr',
// name: 'Français'
// }
]
}
})
Loading

0 comments on commit beb8e58

Please sign in to comment.