@@ -292,27 +292,47 @@ export class WebsocketService {
292292 public mapPowersToHumanReadable ( powers : Array < any > ) : string {
293293 if ( ! Array . isArray ( powers ) || powers . length === 0 ) return '' ;
294294
295+ const unknown = this . translate . instant ( 'common.unknown' ) || 'Desconocido' ;
296+
295297 const lines = powers
296298 . map ( ( p ) => {
297299 const fnKey = this . normalizeKey ( p ?. function ) ;
298300 const actionKeys = this . normalizeActionKeys ( p ?. action ) ;
299301
300- const functionLabel =
301- this . translate . instant ( `vc-fields.power.${ fnKey } ` ) || p ?. function || '' ;
302+ const functionLabelRaw =
303+ this . getSafeTranslation ( `vc-fields.power.${ fnKey } ` , p ?. function , unknown ) ;
304+
305+ const actionLabelsRaw = actionKeys
306+ . map ( ( a ) => this . getSafeTranslation ( `vc-fields.power.${ a } ` , a , unknown ) )
307+ . filter ( ( x ) => x && x !== unknown ) ;
302308
303- const actionLabels = actionKeys
304- . map ( ( a ) => this . translate . instant ( `vc-fields.power.${ a } ` ) || a )
305- . join ( ', ' ) ;
309+ const functionLabel = this . escapeHtml ( functionLabelRaw ) ;
310+ const actionLabels = this . escapeHtml ( actionLabelsRaw . join ( ', ' ) ) ;
306311
307- const line = ` ${ functionLabel } : ${ actionLabels } ` ;
312+ if ( ! functionLabel || ! actionLabels ) return '' ;
308313
309- return line . trim ( ) ;
314+ return ` ${ functionLabel } : ${ actionLabels } ` ;
310315 } )
311316 . filter ( Boolean ) ;
312317
313318 return lines . join ( '<br/>' ) ;
314319 }
315320
321+ private getSafeTranslation ( key : string , fallbackText : unknown , unknown : string ) : string {
322+ const translated = this . translate . instant ( key ) ;
323+
324+ const hasRealTranslation = translated && translated !== key ;
325+
326+ if ( hasRealTranslation ) return String ( translated ) ;
327+
328+ const fb = String ( fallbackText ?? '' ) . trim ( ) ;
329+ const looksLikeKey = fb . includes ( '.' ) || fb . includes ( '_' ) || fb . includes ( '-' ) ;
330+ if ( ! fb || looksLikeKey ) return unknown ;
331+
332+ return fb ;
333+ }
334+
335+
316336
317337 private normalizeKey ( value : unknown ) : string {
318338 return String ( value ?? '' )
0 commit comments