From c691d8ef72465eb04cbcf64cd5d4281f259c4ebf Mon Sep 17 00:00:00 2001 From: Stanyslas Bres Date: Wed, 6 Nov 2019 22:44:30 +0100 Subject: [PATCH 01/11] chore(feat): localize 404 page (fix #1987) --- .../core/lib/node/ClientComputedMixin.js | 2 +- .../fixtures/docs-i18n/.vuepress/config.js | 16 +++++++- .../@vuepress/test-utils/client/siteData.js | 18 ++++++++- .../@vuepress/theme-default/layouts/404.vue | 37 ++++++++++++++----- packages/docs/docs/.vuepress/config.js | 14 +++++++ packages/docs/docs/guide/i18n.md | 5 +++ .../docs/docs/theme/default-theme-config.md | 8 +++- packages/docs/docs/zh/guide/i18n.md | 6 +++ .../docs/zh/theme/default-theme-config.md | 6 ++- 9 files changed, 97 insertions(+), 15 deletions(-) diff --git a/packages/@vuepress/core/lib/node/ClientComputedMixin.js b/packages/@vuepress/core/lib/node/ClientComputedMixin.js index dbe8a3f7a5..a3166805bd 100644 --- a/packages/@vuepress/core/lib/node/ClientComputedMixin.js +++ b/packages/@vuepress/core/lib/node/ClientComputedMixin.js @@ -54,7 +54,7 @@ module.exports = siteData => { for (const path in locales) { if (path === '/') { defaultLang = locales[path] - } else if (this.$page.path.indexOf(path) === 0) { + } else if (this.$page.path.indexOf(path) === 0 || (!this.$page.path && this.$route.path.indexOf(path) === 0)) { targetLang = locales[path] } } diff --git a/packages/@vuepress/core/lib/node/__tests__/prepare/fixtures/docs-i18n/.vuepress/config.js b/packages/@vuepress/core/lib/node/__tests__/prepare/fixtures/docs-i18n/.vuepress/config.js index 1fbdc1cec1..0fd0bd11d5 100644 --- a/packages/@vuepress/core/lib/node/__tests__/prepare/fixtures/docs-i18n/.vuepress/config.js +++ b/packages/@vuepress/core/lib/node/__tests__/prepare/fixtures/docs-i18n/.vuepress/config.js @@ -21,13 +21,27 @@ module.exports = { label: 'English', selectText: 'Languages', editLinkText: 'Edit this page on GitHub', - lastUpdated: 'Last Updated' + lastUpdated: 'Last Updated', + notFoundLinkText: 'Take me home.', + notFoundMessages: [ + `There's nothing here.`, + `How did we get here?`, + `That's a Four-Oh-Four.`, + `Looks like we've got some broken links.` + ] }, '/zh/': { label: '简体中文', selectText: '选择语言', editLinkText: '在 GitHub 上编辑此页', lastUpdated: '上次更新', + notFoundLinkText: 'Take me home.', + notFoundMessages: [ + `There's nothing here.`, + `How did we get here?`, + `That's a Four-Oh-Four.`, + `Looks like we've got some broken links.` + ] } } } diff --git a/packages/@vuepress/test-utils/client/siteData.js b/packages/@vuepress/test-utils/client/siteData.js index 5e3ea16429..cdeb191d95 100644 --- a/packages/@vuepress/test-utils/client/siteData.js +++ b/packages/@vuepress/test-utils/client/siteData.js @@ -29,13 +29,27 @@ export default { "label": "English", "selectText": "Languages", "editLinkText": "Edit this page on GitHub", - "lastUpdated": "Last Updated" + "lastUpdated": "Last Updated", + "notFoundLinkText": "Take me home.", + "notFoundMessages": [ + "There's nothing here.", + "How did we get here?", + "That's a Four-Oh-Four.", + "Looks like we've got some broken links." + ] }, "/zh/": { "label": "简体中文", "selectText": "选择语言", "editLinkText": "在 GitHub 上编辑此页", - "lastUpdated": "上次更新" + "lastUpdated": "上次更新", + "notFoundLinkText": "Take me home.", + "notFoundMessages": [ + "There's nothing here.", + "How did we get here?", + "That's a Four-Oh-Four.", + "Looks like we've got some broken links." + ] } } }, diff --git a/packages/@vuepress/theme-default/layouts/404.vue b/packages/@vuepress/theme-default/layouts/404.vue index 3dc84dcfae..d0b77b0800 100644 --- a/packages/@vuepress/theme-default/layouts/404.vue +++ b/packages/@vuepress/theme-default/layouts/404.vue @@ -3,23 +3,42 @@

404

{{ getMsg() }}
- Take me home. + {{ notFoundLinkText }}