7
7
DevToolsTimelineEvents ,
8
8
DevToolsTimelineLayerMaps
9
9
} from '@intlify/core-base'
10
+ import { isFunction , isObject } from '@intlify/shared'
10
11
11
12
import type { App } from 'vue'
12
13
import type {
@@ -194,7 +195,7 @@ function inspectComposer(
194
195
type,
195
196
key : 'messages' ,
196
197
editable : false ,
197
- value : composer . messages . value
198
+ value : getLocaleMessageValue ( composer . messages . value )
198
199
} )
199
200
instanceData . state . push ( {
200
201
type,
@@ -210,6 +211,48 @@ function inspectComposer(
210
211
} )
211
212
}
212
213
214
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
215
+ function getLocaleMessageValue ( messages : any ) : Record < string , unknown > {
216
+ const value : Record < string , unknown > = { }
217
+ Object . keys ( messages ) . forEach ( ( key : string ) => {
218
+ const v : unknown = messages [ key ]
219
+ if ( isFunction ( v ) && 'source' in v ) {
220
+ value [ key ] = getMessageFunctionDetails ( v )
221
+ } else if ( isObject ( v ) ) {
222
+ value [ key ] = getLocaleMessageValue ( v )
223
+ } else {
224
+ value [ key ] = v
225
+ }
226
+ } )
227
+ return value
228
+ }
229
+
230
+ const ESC : Record < string , string > = {
231
+ '<' : '<' ,
232
+ '>' : '>' ,
233
+ '"' : '"' ,
234
+ '&' : '&'
235
+ }
236
+
237
+ function escape ( s : string ) : string {
238
+ return s . replace ( / [ < > " & ] / g, escapeChar )
239
+ }
240
+
241
+ function escapeChar ( a : string ) : string {
242
+ return ESC [ a ] || a
243
+ }
244
+
245
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
246
+ function getMessageFunctionDetails ( func : any ) : Record < string , unknown > {
247
+ const argString = func . source ? `("${ escape ( func . source ) } ")` : `(?)`
248
+ return {
249
+ _custom : {
250
+ type : 'function' ,
251
+ display : `<span>ƒ</span> ${ argString } `
252
+ }
253
+ }
254
+ }
255
+
213
256
function registerScope <
214
257
Messages ,
215
258
DateTimeFormats ,
@@ -308,7 +351,7 @@ function makeScopeInspectState(composer: Composer): CustomInspectorState {
308
351
type : localeMessagesType ,
309
352
key : 'messages' ,
310
353
editable : false ,
311
- value : composer . messages . value
354
+ value : getLocaleMessageValue ( composer . messages . value )
312
355
}
313
356
]
314
357
state [ localeMessagesType ] = localeMessagesStates
0 commit comments