Skip to content

Commit f10a546

Browse files
pagyewimyelo
authored andcommitted
feat: Add localization
1 parent 9244e39 commit f10a546

File tree

1 file changed

+27
-5
lines changed

1 file changed

+27
-5
lines changed

src/pagination.js

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,22 +131,44 @@ const template = {
131131
},
132132
}
133133

134+
function updateText (options, path) {
135+
['previousText', 'nextText'].forEach(key => {
136+
const text = options[key]
137+
138+
if (typeof text === 'string') {
139+
options[key] = text
140+
} else {
141+
Object.keys(text).some(local => {
142+
const isMatch = path.indexOf(local) > -1
143+
144+
options[key] = isMatch ? text[local] : text
145+
146+
return isMatch
147+
});
148+
}
149+
})
150+
}
151+
134152
/**
135153
* installation
136154
*/
137155
export function install (hook, vm) {
138-
let options = Object.assign(
156+
const options = Object.assign(
139157
{},
140158
DEFAULT_OPTIONS(vm.config),
141159
vm.config.pagination || {}
142160
)
143161

144162
function render () {
145163
const container = query(`.${CONTAINER_CLASSNAME}`)
146-
if (!container) {
147-
return
148-
}
149-
container.innerHTML = template.inner(pagination(vm, options), options)
164+
165+
if (!container) return
166+
167+
const i18n = JSON.parse(JSON.stringify(options))
168+
169+
updateText(i18n, vm.route.path);
170+
171+
container.innerHTML = template.inner(pagination(vm, i18n), i18n)
150172
}
151173

152174
hook.afterEach((html) => html + template.container())

0 commit comments

Comments
 (0)