Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: localize 404 page fix #1987 #2961

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 28 additions & 14 deletions packages/@vuepress/theme-default/layouts/404.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,40 @@

<blockquote>{{ getMsg() }}</blockquote>

<RouterLink to="/">
Take me home.
</RouterLink>
<RouterLink to="/"> Take me home. </RouterLink>
</div>
</div>
</template>

<script>
const msgs = [
`There's nothing here.`,
`How did we get here?`,
`That's a Four-Oh-Four.`,
`Looks like we've got some broken links.`
]
const msgs = {
en: [
`There's nothing here.`,
`How did we get here?`,
`That's a Four-Oh-Four.`,
`Looks like we've got some broken links.`,
],
zh: [
`这里什么都没有。`,
`我们是如何来到这里的?`,
`那是一个4-0-4。`,
`看起来我们有一些破碎的链接。`,
],
};

export default {
methods: {
getMsg () {
return msgs[Math.floor(Math.random() * msgs.length)]
}
}
}
getMsg() {
const localMsgs = this.localizeMsgs();
return localMsgs[Math.floor(Math.random() * localMsgs.length)];
},
localizeMsgs() {
const routesFirstPath = this.$route.path.match("\/.+?\/");
if (routesFirstPath != null && routesFirstPath[0] === "/zh/") {
return msgs.zh;
}
return msgs.en;
},
},
};
</script>