-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Multiple Language Support + Complete Chinese Translation #48
Conversation
Looks good, but I think there are a few extra TODOs:
So the config may need to look a bit different: module.exports = {
langs: [
{ lang: 'en', label: 'English', path: '/', selectText: 'Languages' },
{ lang: 'zh-CN', label: '简体中文', path: '/zh/', selectText: '选择语言' }
],
title: {
'/': 'VuePress',
'/zh/': '中文 title'
},
description: {
'/': 'English description',
'/zh/': '中文 description'
},
themeConfig: {
nav: {
// the language select dropdown is auto generated, so no need to repeat it here
'/': [...],
'/zh/': [...]
}
}
} Edit: I just realized we can make |
Got it, now I can continue to work for it since dropdown has ramped up. |
Completed basically, In addition to fix some bugs you mentioned above, and now supports the following features:
And the only remaining thing is to document Wait for you review comments, thank you. |
To preview https://deploy-preview-48--vuepress.netlify.com/, please clean cache first. |
lib/app/dataMixin.js
Outdated
$langConfig () { | ||
const { langs } = this.$site | ||
let defaultLang | ||
const lang = (langs || []).find((lang, index) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Buble does not polyfill Array.prototype.find
so we have to avoid using it in order to make the site run in IE11.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! all incompatible API issues are fixed at 1c31f82
lib/default-theme/NavLinks.vue
Outdated
// Try to stay on the same page | ||
link = currentLink.replace(this.$langConfig.path, lang.path) | ||
// fallback to homepage | ||
if (!routes.find(route => route.path === link)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same, avoid using Array.prototype.find
(use .some
here instead)
lib/default-theme/NavLinks.vue
Outdated
|
||
export default { | ||
components: { OutboundLink, NavLink, DropdownLink }, | ||
computed: { | ||
userNav() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
space before parens
lib/default-theme/NavLinks.vue
Outdated
} | ||
return this.$site.themeConfig.nav[this.$basepath] | ||
}, | ||
nav() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
space before parens
@@ -43,6 +69,22 @@ module.exports = { | |||
'deploy' | |||
] | |||
} | |||
], | |||
'/zh/guide/': [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sidebar 配置除了 title 之外其实是一样的,可以抽取出来
] | ||
} | ||
``` | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
新加了一个 host 选项,可以补上
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed at b794126
Very nice job again! Only some small things. |
I just found that it has been merged 😂. In fact, I am still working on the automatic extraction of sidebar title for different locales. I'll open another PR for that later today. |
@ulivz oh I didn't mean automatic extraction... I simply used a function inside |
I just went to lunch and stopped working. well, you are right, once I really do that function, it will violate the principle of simplicity. thanks, good night. |
Fixed for #41, and this PR is based on #13.
Though I have read and modified repeatedly, there may still be some places where translation is not detailed enough. If you find it, feel free to leave your comments. Thank you.
Description
Since most users (Vue is also the same) will only consider supporting the main language support at the beginning, so I pass in an array that contains link items to nav:
Then one day, I find I want to add translations for my docs, taking adding Chinese translation as an example, I will need to do the following work to achieve i18n:
.vuepress
Preview
TODO
title
anddescription
field.