Skip to content

Commit cc11b8e

Browse files
authored
fix(theme/i18n): 404 page not showing localized text (#3833)
1 parent 0048787 commit cc11b8e

File tree

3 files changed

+31
-18
lines changed

3 files changed

+31
-18
lines changed

Diff for: .github/workflows/test.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323

2424
strategy:
2525
matrix:
26-
node_version: [18, 20, 21]
26+
node_version: [18, 20, 22]
2727

2828
steps:
2929
- name: Checkout

Diff for: src/client/theme-default/NotFound.vue

+28-17
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,55 @@
11
<script setup lang="ts">
2-
import { onMounted, ref } from 'vue'
2+
import { computed, onMounted, ref } from 'vue'
33
import { withBase } from 'vitepress'
44
import { useData } from './composables/data'
55
import { useLangs } from './composables/langs'
66
7-
const { site, theme } = useData()
7+
const { site } = useData()
88
const { localeLinks } = useLangs({ removeCurrent: false })
99
10-
const root = ref('/')
10+
const locale = ref({
11+
link: '/',
12+
index: 'root'
13+
})
14+
1115
onMounted(() => {
1216
const path = window.location.pathname
1317
.replace(site.value.base, '')
1418
.replace(/(^.*?\/).*$/, '/$1')
1519
if (localeLinks.value.length) {
16-
root.value =
17-
localeLinks.value.find(({ link }) => link.startsWith(path))?.link ||
18-
localeLinks.value[0].link
20+
locale.value =
21+
localeLinks.value.find(({ link }) => link.startsWith(path)) ||
22+
localeLinks.value[0]
1923
}
2024
})
25+
26+
const notFound = computed(() => ({
27+
code: 404,
28+
title: 'PAGE NOT FOUND',
29+
quote:
30+
"But if you don't change your direction, and if you keep looking, you may end up where you are heading.",
31+
linkLabel: 'go to home',
32+
linkText: 'Take me home',
33+
...(locale.value.index === 'root'
34+
? site.value.themeConfig?.notFound
35+
: site.value.locales?.[locale.value.index]?.themeConfig?.notFound)
36+
}))
2137
</script>
2238

2339
<template>
2440
<div class="NotFound">
25-
<p class="code">{{ theme.notFound?.code ?? '404' }}</p>
26-
<h1 class="title">{{ theme.notFound?.title ?? 'PAGE NOT FOUND' }}</h1>
41+
<p class="code">{{ notFound.code }}</p>
42+
<h1 class="title">{{ notFound.title }}</h1>
2743
<div class="divider" />
28-
<blockquote class="quote">
29-
{{
30-
theme.notFound?.quote ??
31-
"But if you don't change your direction, and if you keep looking, you may end up where you are heading."
32-
}}
33-
</blockquote>
44+
<blockquote class="quote">{{ notFound.quote }}</blockquote>
3445

3546
<div class="action">
3647
<a
3748
class="link"
38-
:href="withBase(root)"
39-
:aria-label="theme.notFound?.linkLabel ?? 'go to home'"
49+
:href="withBase(locale.link)"
50+
:aria-label="notFound.linkLabel"
4051
>
41-
{{ theme.notFound?.linkText ?? 'Take me home' }}
52+
{{ notFound.linkText }}
4253
</a>
4354
</div>
4455
</div>

Diff for: src/client/theme-default/composables/langs.ts

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export function useLangs({
88
} = {}) {
99
const { site, localeIndex, page, theme, hash } = useData()
1010
const currentLang = computed(() => ({
11+
index: localeIndex.value,
1112
label: site.value.locales[localeIndex.value]?.label,
1213
link:
1314
site.value.locales[localeIndex.value]?.link ||
@@ -19,6 +20,7 @@ export function useLangs({
1920
removeCurrent && currentLang.value.label === value.label
2021
? []
2122
: {
23+
index: key,
2224
text: value.label,
2325
link:
2426
normalizeLink(

0 commit comments

Comments
 (0)