提交 4480568a 编写于 作者: E Evan You

refactor: langs -> locales

上级 6f5bac08
module.exports = {
dest: 'vuepress',
langs: {
locales: {
'/': {
lang: 'en-US',
label: 'English',
......
......@@ -8,9 +8,9 @@ function prepare (siteData) {
page.frontmatter = {}
}
})
if (siteData.langs) {
Object.keys(siteData.langs).forEach(path => {
siteData.langs[path].path = path
if (siteData.locales) {
Object.keys(siteData.locales).forEach(path => {
siteData.locales[path].path = path
})
}
Object.freeze(siteData)
......@@ -33,30 +33,30 @@ export default {
$site () {
return store.siteData
},
$langConfig () {
const { langs } = this.$site
$localeConfig () {
const { locales } = this.$site
let targetLang
let defaultLang
Object.keys(langs).forEach(path => {
Object.keys(locales).forEach(path => {
if (path === '/') {
defaultLang = langs[path]
defaultLang = locales[path]
} else if (this.$page.path.indexOf(path) === 0) {
targetLang = langs[path]
targetLang = locales[path]
}
})
return targetLang || defaultLang || {}
},
$title () {
return this.$langConfig.title || this.$site.title || ''
return this.$localeConfig.title || this.$site.title || ''
},
$description () {
return this.$langConfig.description || this.$site.description || ''
return this.$localeConfig.description || this.$site.description || ''
},
$lang () {
return this.$langConfig.lang || 'en-US'
return this.$localeConfig.lang || 'en-US'
},
$localePath () {
return this.$langConfig.path || '/'
return this.$localeConfig.path || '/'
},
$page () {
return findPageForPath(
......
......@@ -36,13 +36,14 @@ export default {
return []
},
nav () {
if (this.$site.langs) {
const { locales } = this.$site
if (locales) {
let currentLink = this.$page.path
const routes = this.$router.options.routes
const languageDropdown = {
text: this.$langConfig.selectText,
items: Object.keys(this.$site.langs).map(path => {
const locale = this.$site.langs[path]
text: this.$localeConfig.selectText,
items: Object.keys(locales).map(path => {
const locale = locales[path]
const text = locale.label
let link
// Stay on the current page
......@@ -50,7 +51,7 @@ export default {
link = currentLink
} else {
// Try to stay on the same page
link = currentLink.replace(this.$langConfig.path, path)
link = currentLink.replace(this.$localeConfig.path, path)
// fallback to homepage
if (!routes.some(route => route.path === link)) {
link = path
......
......@@ -92,11 +92,11 @@ export default {
},
methods: {
getPageLocalePath (page) {
const { langs } = this.$site
for (let i = 0; i < langs.length; i++) {
const localePath = langs[i].path
const { locales } = this.$site
for (let i = 0; i < locales.length; i++) {
const localePath = locales[i].path
if (localePath !== '/' && page.path.indexOf(localePath) === 0) {
return langs[i].path
return locales[i].path
}
}
return '/'
......
......@@ -188,7 +188,7 @@ async function resolveOptions (sourceDir) {
base: siteConfig.base || '/',
pages: pagesData,
themeConfig: siteConfig.themeConfig || {},
langs: siteConfig.langs
locales: siteConfig.locales
}
return options
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册