Skip to content

Commit 4480568

Browse files
committed
refactor: langs -> locales
1 parent 6f5bac0 commit 4480568

File tree

5 files changed

+24
-23
lines changed

5 files changed

+24
-23
lines changed

docs/.vuepress/config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module.exports = {
22
dest: 'vuepress',
3-
langs: {
3+
locales: {
44
'/': {
55
lang: 'en-US',
66
label: 'English',

lib/app/dataMixin.js

+12-12
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ function prepare (siteData) {
88
page.frontmatter = {}
99
}
1010
})
11-
if (siteData.langs) {
12-
Object.keys(siteData.langs).forEach(path => {
13-
siteData.langs[path].path = path
11+
if (siteData.locales) {
12+
Object.keys(siteData.locales).forEach(path => {
13+
siteData.locales[path].path = path
1414
})
1515
}
1616
Object.freeze(siteData)
@@ -33,30 +33,30 @@ export default {
3333
$site () {
3434
return store.siteData
3535
},
36-
$langConfig () {
37-
const { langs } = this.$site
36+
$localeConfig () {
37+
const { locales } = this.$site
3838
let targetLang
3939
let defaultLang
40-
Object.keys(langs).forEach(path => {
40+
Object.keys(locales).forEach(path => {
4141
if (path === '/') {
42-
defaultLang = langs[path]
42+
defaultLang = locales[path]
4343
} else if (this.$page.path.indexOf(path) === 0) {
44-
targetLang = langs[path]
44+
targetLang = locales[path]
4545
}
4646
})
4747
return targetLang || defaultLang || {}
4848
},
4949
$title () {
50-
return this.$langConfig.title || this.$site.title || ''
50+
return this.$localeConfig.title || this.$site.title || ''
5151
},
5252
$description () {
53-
return this.$langConfig.description || this.$site.description || ''
53+
return this.$localeConfig.description || this.$site.description || ''
5454
},
5555
$lang () {
56-
return this.$langConfig.lang || 'en-US'
56+
return this.$localeConfig.lang || 'en-US'
5757
},
5858
$localePath () {
59-
return this.$langConfig.path || '/'
59+
return this.$localeConfig.path || '/'
6060
},
6161
$page () {
6262
return findPageForPath(

lib/default-theme/NavLinks.vue

+6-5
Original file line numberDiff line numberDiff line change
@@ -36,21 +36,22 @@ export default {
3636
return []
3737
},
3838
nav () {
39-
if (this.$site.langs) {
39+
const { locales } = this.$site
40+
if (locales) {
4041
let currentLink = this.$page.path
4142
const routes = this.$router.options.routes
4243
const languageDropdown = {
43-
text: this.$langConfig.selectText,
44-
items: Object.keys(this.$site.langs).map(path => {
45-
const locale = this.$site.langs[path]
44+
text: this.$localeConfig.selectText,
45+
items: Object.keys(locales).map(path => {
46+
const locale = locales[path]
4647
const text = locale.label
4748
let link
4849
// Stay on the current page
4950
if (locale.lang === this.$lang) {
5051
link = currentLink
5152
} else {
5253
// Try to stay on the same page
53-
link = currentLink.replace(this.$langConfig.path, path)
54+
link = currentLink.replace(this.$localeConfig.path, path)
5455
// fallback to homepage
5556
if (!routes.some(route => route.path === link)) {
5657
link = path

lib/default-theme/SearchBox.vue

+4-4
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,11 @@ export default {
9292
},
9393
methods: {
9494
getPageLocalePath (page) {
95-
const { langs } = this.$site
96-
for (let i = 0; i < langs.length; i++) {
97-
const localePath = langs[i].path
95+
const { locales } = this.$site
96+
for (let i = 0; i < locales.length; i++) {
97+
const localePath = locales[i].path
9898
if (localePath !== '/' && page.path.indexOf(localePath) === 0) {
99-
return langs[i].path
99+
return locales[i].path
100100
}
101101
}
102102
return '/'

lib/prepare.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ async function resolveOptions (sourceDir) {
188188
base: siteConfig.base || '/',
189189
pages: pagesData,
190190
themeConfig: siteConfig.themeConfig || {},
191-
langs: siteConfig.langs
191+
locales: siteConfig.locales
192192
}
193193

194194
return options

0 commit comments

Comments
 (0)