Skip to content

Commit

Permalink
feat(search): Localization for no data tip, close #103
Browse files Browse the repository at this point in the history
  • Loading branch information
QingWei-Li committed Feb 28, 2017
1 parent f3fc596 commit d3c9fbd
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 1 deletion.
8 changes: 8 additions & 0 deletions docs/plugins.md
Expand Up @@ -27,6 +27,14 @@ By default, the hyperlink on the current page is recognized and the content is s
placeholder: {
'/zh-cn/': '搜索',
'/': 'Type to search'
},
noData: 'No Results!',
// Localization
noData: {
'/zh-cn/': '找不到结果',
'/': 'No Results'
}
}
}
Expand Down
8 changes: 8 additions & 0 deletions docs/zh-cn/plugins.md
Expand Up @@ -27,6 +27,14 @@
placeholder: {
'/zh-cn/': '搜索',
'/': 'Type to search'
},
noData: 'No Results!',
// 支持本地化
noData: {
'/zh-cn/': '找不到结果',
'/': 'No Results'
}
}
}
Expand Down
13 changes: 12 additions & 1 deletion src/plugins/search/component.js
@@ -1,6 +1,7 @@
import { search } from './search'

let dom
let NO_DATA_TEXT = ''

function style () {
const code = `
Expand Down Expand Up @@ -98,7 +99,7 @@ function bindEvents () {
})

$panel.classList.add('show')
$panel.innerHTML = html || '<p class="empty">No Results!</p>'
$panel.innerHTML = html || `<p class="empty">${NO_DATA_TEXT}</p>`
}

let timeId
Expand All @@ -122,6 +123,15 @@ function updatePlaceholder (text, path) {
}
}

function updateNoData (text, path) {
if (typeof text === 'string') {
NO_DATA_TEXT = text
} else {
const match = Object.keys(text).find(key => path.indexOf(key) > -1)
NO_DATA_TEXT = text[match]
}
}

export function init (opts) {
dom = Docsify.dom
style()
Expand All @@ -131,5 +141,6 @@ export function init (opts) {

export function update (opts, vm) {
updatePlaceholder(opts.placeholder, vm.route.path)
updateNoData(opts.noData, vm.route.path)
}

2 changes: 2 additions & 0 deletions src/plugins/search/index.js
Expand Up @@ -3,6 +3,7 @@ import { init as initSearch } from './search'

const CONFIG = {
placeholder: 'Type to search',
noData: 'No Results!',
paths: 'auto',
maxAge: 86400000 // 1 day
}
Expand All @@ -17,6 +18,7 @@ const install = function (hook, vm) {
CONFIG.paths = Array.isArray(opts.paths) ? opts.paths : 'auto'
CONFIG.maxAge = util.isPrimitive(opts.maxAge) ? opts.maxAge : CONFIG.maxAge
CONFIG.placeholder = opts.placeholder || CONFIG.placeholder
CONFIG.noData = opts.noData || CONFIG.noData
}

const isAuto = CONFIG.paths === 'auto'
Expand Down

0 comments on commit d3c9fbd

Please sign in to comment.