@@ -82,6 +82,7 @@ function pagination (vm, { crossChapter, routerMode }) {
82
82
const links = crossChapter ? all : group
83
83
84
84
return {
85
+ route : vm . route ,
85
86
prev : new Link ( links [ index - 1 ] ) . toJSON ( ) ,
86
87
next : new Link ( links [ index + 1 ] ) . toJSON ( ) ,
87
88
}
@@ -96,6 +97,7 @@ const template = {
96
97
} ,
97
98
98
99
inner ( data , options ) {
100
+ const { previousText, nextText } = getLocalizationTexts ( options , data . route . path )
99
101
return [
100
102
data . prev && `
101
103
<div class="pagination-item pagination-item--previous">
@@ -104,7 +106,7 @@ const template = {
104
106
<svg width="10" height="16" viewBox="0 0 10 16" xmlns="http://www.w3.org/2000/svg">
105
107
<polyline fill="none" vector-effect="non-scaling-stroke" points="8,2 2,8 8,14"/>
106
108
</svg>
107
- <span>${ options . previousText } </span>
109
+ <span>${ previousText } </span>
108
110
</div>
109
111
<div class="pagination-item-title">${ data . prev . name } </div>
110
112
` ,
@@ -116,7 +118,7 @@ const template = {
116
118
<div class="pagination-item pagination-item--next">
117
119
<a href="${ data . next . href } ">
118
120
<div class="pagination-item-label">
119
- <span>${ options . nextText } </span>
121
+ <span>${ nextText } </span>
120
122
<svg width="10" height="16" viewBox="0 0 10 16" xmlns="http://www.w3.org/2000/svg">
121
123
<polyline fill="none" vector-effect="non-scaling-stroke" points="2,2 8,8 2,14"/>
122
124
</svg>
@@ -131,22 +133,24 @@ const template = {
131
133
} ,
132
134
}
133
135
134
- function updateText ( options , path ) {
135
- [ 'previousText' , 'nextText' ] . forEach ( key => {
136
+ function getLocalizationTexts ( options , path ) {
137
+ const texts = { }
138
+ ; [ 'previousText' , 'nextText' ] . forEach ( key => {
136
139
const text = options [ key ]
137
140
138
141
if ( typeof text === 'string' ) {
139
- options [ key ] = text
142
+ texts [ key ] = text
140
143
} else {
141
144
Object . keys ( text ) . some ( local => {
142
145
const isMatch = path . indexOf ( local ) > - 1
143
146
144
- options [ key ] = isMatch ? text [ local ] : text
147
+ texts [ key ] = isMatch ? text [ local ] : text
145
148
146
149
return isMatch
147
- } ) ;
150
+ } )
148
151
}
149
152
} )
153
+ return texts
150
154
}
151
155
152
156
/**
@@ -164,11 +168,7 @@ export function install (hook, vm) {
164
168
165
169
if ( ! container ) return
166
170
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 )
171
+ container . innerHTML = template . inner ( pagination ( vm , options ) , options )
172
172
}
173
173
174
174
hook . afterEach ( ( html ) => html + template . container ( ) )
0 commit comments