File tree Expand file tree Collapse file tree 3 files changed +26
-1
lines changed Expand file tree Collapse file tree 3 files changed +26
-1
lines changed Original file line number Diff line number Diff line change @@ -338,7 +338,14 @@ export class I18n {
338
338
*/
339
339
wTrans ( key : string , replacements : ReplacementsInterface = { } ) : ComputedRef < string > {
340
340
if ( ! this . activeMessages [ key ] ) {
341
- this . activeMessages [ key ] = key
341
+ const hasChildItems = this . activeMessages [ `${ key } .0` ] !== undefined ;
342
+
343
+ if ( hasChildItems ) {
344
+ const childItems = Object . entries ( this . activeMessages ) . filter ( ( item ) => item [ 0 ] . startsWith ( `${ key } .` ) ) . map ( item => item [ 1 ] ) ;
345
+ this . activeMessages [ key ] = reactive ( childItems ) ;
346
+ } else {
347
+ this . activeMessages [ key ] = key ;
348
+ }
342
349
}
343
350
344
351
return computed ( ( ) => this . makeReplacements ( this . activeMessages [ key ] , replacements ) )
Original file line number Diff line number Diff line change
1
+ {
2
+ "auth.arr.0" : " foo" ,
3
+ "auth.arr.1" : " bar"
4
+ }
Original file line number Diff line number Diff line change @@ -173,3 +173,17 @@ it('resolves translated data with loader if there is only .php files for that la
173
173
174
174
expect ( wrapper . html ( ) ) . toBe ( '<h1>Ces identifiants ne correspondent pas à nos enregistrements.</h1>' )
175
175
} )
176
+
177
+
178
+ it ( 'translates arrays with $t mixin' , async ( ) => {
179
+ const wrapper = await global . mountPlugin ( `<h1 v-for="line in $t('auth.arr')">{{line}}</h1>` , 'de' ) ;
180
+
181
+ expect ( wrapper . html ( ) ) . toBe ( "<h1>foo</h1>\n<h1>bar</h1>" )
182
+ } )
183
+
184
+ it ( 'translates arrays with "trans" helper' , async ( ) => {
185
+ await global . mountPlugin ( undefined , 'de' ) ;
186
+
187
+ expect ( trans ( 'auth.arr' ) ) . toStrictEqual ( [ 'foo' , 'bar' ] ) ;
188
+ } )
189
+
You can’t perform that action at this time.
0 commit comments