File tree Expand file tree Collapse file tree 4 files changed +2
-106
lines changed Expand file tree Collapse file tree 4 files changed +2
-106
lines changed Original file line number Diff line number Diff line change @@ -321,50 +321,3 @@ export function resolveValue(obj: unknown, path: Path): PathValue {
321321
322322 return last
323323}
324-
325- /**
326- * Transform flat json in obj to normal json in obj
327- */
328- export function handleFlatJson ( obj : unknown ) : unknown {
329- // check obj
330- if ( ! isObject ( obj ) ) {
331- return obj
332- }
333-
334- for ( const key in obj as object ) {
335- // check key
336- if ( ! obj . hasOwnProperty ( key ) ) {
337- continue
338- }
339-
340- // handle for normal json
341- if ( ! key . includes ( PathCharTypes . DOT ) ) {
342- // recursive process value if value is also a object
343- if ( typeof obj [ key ] === 'object' ) {
344- handleFlatJson ( obj [ key ] )
345- }
346- }
347- // handle for flat json, transform to normal json
348- else {
349- // go to the last object
350- const subKeys = key . split ( PathCharTypes . DOT )
351- const lastIndex = subKeys . length - 1
352- let currentObj = obj
353- for ( let i = 0 ; i < lastIndex ; i ++ ) {
354- if ( ! ( subKeys [ i ] in currentObj ) ) {
355- currentObj [ subKeys [ i ] ] = { }
356- }
357- currentObj = currentObj [ subKeys [ i ] ]
358- }
359- // update last object value, delete old property
360- currentObj [ subKeys [ lastIndex ] ] = obj [ key ]
361- delete obj [ key ]
362- // recursive process value if value is also a object
363- if ( typeof currentObj [ subKeys [ lastIndex ] ] === 'object' ) {
364- handleFlatJson ( currentObj [ subKeys [ lastIndex ] ] )
365- }
366- }
367- }
368-
369- return obj
370- }
Original file line number Diff line number Diff line change 1- import { parse , resolveValue , handleFlatJson } from '../src/index'
1+ import { parse , resolveValue } from '../src/index'
22
33test ( 'parse' , ( ) => {
44 expect ( parse ( 'a' ) ) . toEqual ( [ 'a' ] )
@@ -121,29 +121,3 @@ test('resolveValue', () => {
121121 // blanket middle
122122 expect ( resolveValue ( { } , 'a.b.c[]d' ) ) . toEqual ( null )
123123} )
124-
125- test ( 'handleFlatJson' , ( ) => {
126- const obj = {
127- a : { a1 : 'a1.value' } ,
128- 'a.a2' : 'a.a2.value' ,
129- 'b.x' : {
130- 'b1.x' : 'b1.x.value' ,
131- 'b2.x' : [ 'b2.x.value0' , 'b2.x.value1' ] ,
132- 'b3.x' : { 'b3.x' : 'b3.x.value' }
133- }
134- }
135-
136- handleFlatJson ( obj )
137-
138- expect ( obj [ 'a' ] [ 'a1' ] === 'a1.value' ) . toEqual ( true )
139- // @ts -ignore
140- expect ( obj [ 'a' ] [ 'a2' ] === 'a.a2.value' ) . toEqual ( true )
141- // @ts -ignore
142- expect ( obj [ 'b' ] [ 'x' ] [ 'b1' ] [ 'x' ] === 'b1.x.value' ) . toEqual ( true )
143- // @ts -ignore
144- expect ( obj [ 'b' ] [ 'x' ] [ 'b2' ] [ 'x' ] [ 0 ] === 'b2.x.value0' ) . toEqual ( true )
145- // @ts -ignore
146- expect ( obj [ 'b' ] [ 'x' ] [ 'b2' ] [ 'x' ] [ 1 ] === 'b2.x.value1' ) . toEqual ( true )
147- // @ts -ignore
148- expect ( obj [ 'b' ] [ 'x' ] [ 'b3' ] [ 'x' ] [ 'b3' ] [ 'x' ] === 'b3.x.value' ) . toEqual ( true )
149- } )
Original file line number Diff line number Diff line change @@ -32,8 +32,7 @@ import {
3232 parseNumberArgs ,
3333 clearNumberFormat ,
3434 NOT_REOSLVED ,
35- DevToolsTimelineEvents ,
36- handleFlatJson
35+ DevToolsTimelineEvents
3736} from '@intlify/core-base'
3837import { I18nWarnCodes , getWarnMessage } from './warnings'
3938import { I18nErrorCodes , createI18nError } from './errors'
@@ -960,13 +959,6 @@ export function getLocaleMessages<Message = VueMessageType>(
960959 } )
961960 }
962961
963- // handle messages for flat json
964- for ( const key in ret ) {
965- if ( ret . hasOwnProperty ( key ) ) {
966- handleFlatJson ( ret [ key ] )
967- }
968- }
969-
970962 return ret
971963}
972964
Original file line number Diff line number Diff line change @@ -27,29 +27,6 @@ describe('createI18n', () => {
2727
2828 expect ( i18n . mode ) . toEqual ( 'composition' )
2929 } )
30-
31- test ( 'flat json message in legacy mode' , ( ) => {
32- const i18n = createI18n ( {
33- messages : {
34- en : { 'mainMenu.buttonStart' : 'Start!' }
35- }
36- } )
37- const messages = i18n . global . messages
38- // @ts -ignore
39- expect ( messages [ 'en' ] [ 'mainMenu' ] [ 'buttonStart' ] === 'Start!' ) . toEqual ( true )
40- } )
41-
42- test ( 'flat json message in composition mode' , ( ) => {
43- const i18n = createI18n ( {
44- legacy : false ,
45- messages : {
46- en : { 'mainMenu.buttonStart' : 'Start!' }
47- }
48- } )
49- const messages = i18n . global . messages . value
50- // @ts -ignore
51- expect ( messages [ 'en' ] [ 'mainMenu' ] [ 'buttonStart' ] === 'Start!' ) . toEqual ( true )
52- } )
5330} )
5431
5532describe ( 'useI18n' , ( ) => {
You can’t perform that action at this time.
0 commit comments