Skip to content

Commit 5574fe0

Browse files
antfuubugeeeiaster-mnchk-miyakeperaichi-fujishiro
authored
feat: add basic i18n support, and port Japanese content from vuejs-jp/learn.nuxt.com (#217)
Co-authored-by: ubugeeei <[email protected]> Co-authored-by: aster-mnch <[email protected]> Co-authored-by: k-miyake <[email protected]> Co-authored-by: peraichi-fujishiro <[email protected]> Co-authored-by: kotafujishiro <[email protected]> Co-authored-by: rexhent <[email protected]> Co-authored-by: Archetipo95 <[email protected]> Co-authored-by: tokuda109 <[email protected]> Co-authored-by: shiyuu33 <[email protected]> Co-authored-by: arashsheyda <[email protected]> Co-authored-by: RihanArfan <[email protected]> Co-authored-by: atlansien <[email protected]> Co-authored-by: 2nofa11 <[email protected]> Co-authored-by: engineer-naito <[email protected]> Co-authored-by: hiro-xre <[email protected]> Co-authored-by: johnsoncodehk <[email protected]> Co-authored-by: abstractHunter <[email protected]> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
1 parent 9862b79 commit 5574fe0

File tree

190 files changed

+2395
-39
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

190 files changed

+2395
-39
lines changed

.vscode/settings.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,13 @@
3434
"json",
3535
"jsonc",
3636
"yaml"
37-
]
37+
],
38+
"i18n-ally.enabledFrameworks": [
39+
"vue"
40+
],
41+
"i18n-ally.localesPaths": [
42+
"i18n/locales"
43+
],
44+
"i18n-ally.keystyle": "nested",
45+
"i18n-ally.sourceLanguage": "en"
3846
}

components/ColorSchemeToggle.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ function toggleMode() {
88
addCommands(
99
{
1010
id: 'toggle-color-mode',
11-
title: colorMode.value === 'light'
12-
? 'Switch to dark mode'
13-
: 'Switch to light mode',
11+
title: () => colorMode.value === 'light'
12+
? $t('color-mode.to-dark')
13+
: $t('color-mode.to-light'),
1414
handler: toggleMode,
1515
icon: colorMode.value === 'light'
1616
? 'i-ph-moon-stars-duotone'

components/CommandPalette.vue

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ function scrollIntoView(elOrComponent?: any) {
3232
})
3333
}
3434
35+
function getTitle(command: Command) {
36+
if (typeof command.title === 'function')
37+
return command.title()
38+
return command.title
39+
}
40+
3541
// Reset selected when search changes
3642
watch(
3743
() => commands.search,
@@ -102,23 +108,23 @@ useEventListener('keydown', (e) => {
102108
ref="input"
103109
v-model="commands.search"
104110
h-full w-full rounded border-none p4 pl0 outline-none bg-base
105-
placeholder="Search..."
111+
:placeholder="$t('search-dots')"
106112
>
107113
</div>
108114

109115
<div border="t base" flex="~ col" of-y-auto py2>
110116
<component
111117
:is="c.to ? NuxtLink : 'button'"
112-
v-for="c, idx in commands.commandsResult"
113-
:key="c.id || c.title"
118+
v-for="c, idx of commands.commandsResult"
119+
:key="c.id || getTitle(c)"
114120
:ref="(el: Element) => selected === idx && scrollIntoView(el)"
115121
:to="c.to" flex="~ gap-2 items-center" mx1 rounded p2
116122
px3
117123
:class="selected === idx ? 'bg-active' : ''"
118124
@click="runCommand(c)"
119125
>
120126
<div :class="c.icon || 'i-ph-dot-duotone'" />
121-
{{ c.title }}
127+
{{ getTitle(c) }}
122128
</component>
123129
</div>
124130
</div>

components/PanelDocs.vue

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,20 @@ import type { ContentNavigationItem } from '@nuxt/content'
33
44
const runtime = useRuntimeConfig()
55
const route = useRoute()
6-
const { data: page } = useAsyncData(route.path, () => {
7-
return queryCollection('tutorials').path(route.path).first()
6+
const { locale } = useI18n()
7+
8+
const collection = computed(() => locale.value === 'ja' ? 'ja' : 'en')
9+
10+
const { data: page } = useAsyncData(`${locale.value}-${route.path}`, () => {
11+
return queryCollection(collection.value)
12+
.path(route.path)
13+
.first()
814
})
9-
const { data: navigation } = useAsyncData(`navigation`, () => {
10-
return queryCollectionNavigation('tutorials')
15+
const { data: navigation } = useAsyncData(`${locale.value}-navigation`, () => {
16+
return queryCollectionNavigation(collection.value)
1117
})
12-
const { data: surroundings } = useAsyncData(`${route.path}-surroundings`, () => {
13-
return queryCollectionItemSurroundings('tutorials', route.path, {
18+
const { data: surroundings } = useAsyncData(`${locale.value}-${route.path}-surroundings`, () => {
19+
return queryCollectionItemSurroundings(collection.value, route.path, {
1420
fields: ['title', 'description'],
1521
})
1622
})
@@ -55,7 +61,7 @@ const breadcrumbs = computed(() => {
5561
5662
if (!breadcrumbs.find(i => i.path === '/')) {
5763
breadcrumbs.unshift({
58-
title: 'Guide',
64+
title: $t('guide'),
5965
path: '/',
6066
})
6167
}
@@ -134,7 +140,7 @@ router.beforeEach(() => {
134140
hover="text-primary op100"
135141
>
136142
<div i-ph-note-pencil-duotone />
137-
Edit this page
143+
{{ $t('edit-this-page') }}
138144
</NuxtLink>
139145
</div>
140146
</article>

components/PanelPreviewLoading.vue

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ function getTextClass(status: PlaygroundStatus) {
5151
<template v-if="play.status === 'interactive'">
5252
<div flex="~ gap-2 items-center" text-lg>
5353
<div i-ph-terminal-window-duotone text-2xl />
54-
Interactive terminal mode
54+
{{ $t('interactive-terminal-mode') }}
5555
</div>
5656
<button
5757
title="Restart terminal"
@@ -61,20 +61,20 @@ function getTextClass(status: PlaygroundStatus) {
6161
@click="play.restartServer()"
6262
>
6363
<div i-ph-arrow-clockwise-duotone text-lg />
64-
Restart the server
64+
{{ $t('restart-server') }}
6565
</button>
6666
</template>
6767
<div v-else grid="~ cols-[max-content_1fr] gap-2 items-center justify-center">
6868
<div :class="getStatusIcon('init')" />
69-
<span :class="getTextClass('init')">Initializing WebContainer</span>
69+
<span :class="getTextClass('init')">{{ $t('steps.initializing-webcontainer') }}</span>
7070
<div :class="getStatusIcon('mount')" />
71-
<span :class="getTextClass('mount')">Mounting files</span>
71+
<span :class="getTextClass('mount')">{{ $t('steps.mounting-files') }}</span>
7272
<div :class="getStatusIcon('install')" />
73-
<span :class="getTextClass('install')">Installing dependencies</span>
73+
<span :class="getTextClass('install')">{{ $t('steps.installing-dependencies') }}</span>
7474
<div :class="getStatusIcon('start')" />
75-
<span :class="getTextClass('start')">Starting Nuxt server</span>
75+
<span :class="getTextClass('start')">{{ $t('steps.starting-nuxt-server') }}</span>
7676
<div :class="getStatusIcon('polling')" />
77-
<span :class="getTextClass('polling')">Waiting for Nuxt to ready</span>
77+
<span :class="getTextClass('polling')">{{ $t('steps.waiting-for-nuxt-to-ready') }}</span>
7878
</div>
7979
</div>
8080
</template>

components/PanelTerminal.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,19 @@ const play = usePlaygroundStore()
1111
bg-faded p2 pl4
1212
>
1313
<div i-ph-terminal-window-duotone />
14-
<span text-sm>Terminal</span>
14+
<span text-sm>{{ $t('terminal.name') }}</span>
1515
<div flex-auto />
1616
<button
1717
v-if="play.status !== 'init' && play.status !== 'mount'"
1818
hover="bg-active" rounded p1
19-
title="Restart terminal"
19+
:title="$t('terminal.restart')"
2020
@click="play.restartServer()"
2121
>
2222
<div i-ph-arrow-clockwise-duotone />
2323
</button>
2424
<button
2525
hover="bg-active" rounded p1
26-
title="Hide terminal"
26+
:title="$t('terminal.hide')"
2727
@click="ui.toggleTerminal()"
2828
>
2929
<div i-ph-x-bold />

components/TheNav.vue

Lines changed: 52 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,12 @@ function downloadCurrentGuide() {
2121
downloadZip(play.webcontainer, guide.ignoredFiles)
2222
}
2323
24+
const i18n = useI18n()
25+
2426
addCommands(
2527
{
2628
id: 'download-zip',
27-
title: 'Download playground as ZIP',
29+
title: () => $t('download-zip'),
2830
visible: () => {
2931
return play.status === 'ready' && guide.features.download !== false
3032
},
@@ -35,12 +37,34 @@ addCommands(
3537
},
3638
{
3739
id: 'toggle-terminal',
38-
title: 'Toggle terminal',
40+
title: () => $t('terminal.toggle'),
3941
handler: () => {
4042
ui.toggleTerminal()
4143
},
4244
icon: 'i-ph-terminal-window-duotone',
4345
},
46+
{
47+
id: 'language-en',
48+
title: 'Change to English',
49+
handler: () => {
50+
i18n.setLocale('en')
51+
},
52+
icon: 'i-ph-globe-duotone',
53+
visible: () => {
54+
return i18n.locale.value !== 'en'
55+
},
56+
},
57+
{
58+
id: 'language-ja',
59+
title: '日本語に切り替える',
60+
handler: () => {
61+
i18n.setLocale('ja')
62+
},
63+
icon: 'i-ph-globe-duotone',
64+
visible: () => {
65+
return i18n.locale.value !== 'ja'
66+
},
67+
},
4468
)
4569
</script>
4670

@@ -56,7 +80,7 @@ addCommands(
5680
target="_blank"
5781
>
5882
<div block translate-y--2 rounded bg-orange:10 px2 py1 text-xs text-orange>
59-
Work in Progress
83+
{{ $t('work-in-progress') }}
6084
</div>
6185
</NuxtLink>
6286

@@ -65,10 +89,32 @@ addCommands(
6589
flex="~ gap-1 items-center"
6690
:class="guide.embeddedDocs ? 'z-embedded-docs-raised' : ''"
6791
>
92+
<VDropdown :distance="6">
93+
<button
94+
rounded p2
95+
hover="bg-active"
96+
title="Languages"
97+
>
98+
<div i-ph-translate-duotone text-2xl />
99+
</button>
100+
<template #popper>
101+
<div flex="~ col gap-y-1" p2>
102+
<button
103+
v-for="locale of i18n.locales.value" :key="locale.code"
104+
rounded px2 py1
105+
hover="bg-active"
106+
:class="locale.code === i18n.locale.value ? 'text-primary' : ''"
107+
@click="i18n.setLocale(locale.code)"
108+
>
109+
{{ locale.name }}
110+
</button>
111+
</div>
112+
</template>
113+
</VDropdown>
68114
<button
69115
rounded p2
70116
hover="bg-active"
71-
title="Search"
117+
:title="$t('search')"
72118
@click="commands.isShown = true"
73119
>
74120
<div i-ph-magnifying-glass-duotone text-2xl />
@@ -77,7 +123,7 @@ addCommands(
77123
v-if="play.status === 'ready' && !!guide.features.download"
78124
rounded p2
79125
hover="bg-active"
80-
title="Download as ZIP"
126+
:title="$t('download-zip')"
81127
@click="downloadCurrentGuide()"
82128
>
83129
<div i-ph-download-duotone text-2xl />
@@ -103,7 +149,7 @@ addCommands(
103149
</VDropdown>
104150
<button
105151
rounded p2
106-
title="Toggle terminal"
152+
:title="$t('terminal.toggle')"
107153
hover="bg-active"
108154
:class="ui.showTerminal ? '' : 'op50'"
109155
@click="ui.toggleTerminal()"

components/content/ButtonShowSolution.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ const guide = useGuideStore()
1010
>
1111
<div v-if="!guide.showingSolution " i-ph-lightbulb-filament-duotone />
1212
<div v-else i-ph-arrow-counter-clockwise-duotone />
13-
{{ guide.showingSolution ? 'Reset challenge' : 'Show solution' }}
13+
{{ guide.showingSolution ? $t('reset-challenge') : $t('show-solution') }}
1414
</button>
1515
</template>

components/content/ContentCard.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ defineProps<{
1919
<div class="my-0 text-lg font-semibold">
2020
{{ title }}
2121
<sup v-if="wip" rounded bg-primary:10 px1 text-sm text-primary font-normal>
22-
Coming Soon
22+
{{ $t('coming-soon') }}
2323
</sup>
2424
</div>
2525
<div class="mb-0 mt-1 text-[15px] op50">

content.config.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,17 @@ import { defineCollection, defineContentConfig } from '@nuxt/content'
22

33
export default defineContentConfig({
44
collections: {
5-
tutorials: defineCollection({
5+
en: defineCollection({
66
type: 'page',
77
source: {
8-
include: '**',
8+
include: 'en/**',
9+
exclude: ['**/.template/**'],
10+
},
11+
}),
12+
ja: defineCollection({
13+
type: 'page',
14+
source: {
15+
include: 'ja/**',
916
exclude: ['**/.template/**'],
1017
},
1118
}),

0 commit comments

Comments
 (0)