@@ -6,8 +6,6 @@ import { TranslationService } from '../services/TranslationService';
66import { MouseEventHandler } from './MouseEventHandler' ;
77
88export class TranslationHighlighter {
9- private _renderer : any ;
10-
119 constructor (
1210 private service : CoreService ,
1311 private properties : Properties ,
@@ -16,6 +14,31 @@ export class TranslationHighlighter {
1614 private mouseEventHandler : MouseEventHandler
1715 ) { }
1816
17+ private _renderer : any ;
18+
19+ private get renderer ( ) {
20+ if ( this . _renderer === undefined ) {
21+ if ( typeof this . properties . config . ui === 'function' ) {
22+ this . _renderer = new this . properties . config . ui ( {
23+ coreService : this . service ,
24+ properties : this . properties ,
25+ eventService : this . eventService ,
26+ translationService : this . translationService ,
27+ } ) ;
28+ }
29+ }
30+ return this . _renderer ;
31+ }
32+
33+ private static getKeyOptions ( node : ElementWithMeta ) : Set < string > {
34+ const nodes = Array . from ( node . _tolgee . nodes ) ;
35+ const keys = nodes . reduce (
36+ ( acc , curr ) => [ ...acc , ...curr . _tolgee . keys . map ( ( k ) => k . key ) ] ,
37+ [ ]
38+ ) ;
39+ return new Set ( keys ) ;
40+ }
41+
1942 listen ( element : ElementWithMeta & ElementCSSInlineStyle ) {
2043 this . mouseEventHandler . handle (
2144 element ,
@@ -27,6 +50,9 @@ export class TranslationHighlighter {
2750 mouseEvent : MouseEvent ,
2851 element : ElementWithMeta
2952 ) : Promise < string > {
53+ if ( element . _tolgee . wrappedWithElementOnlyKey ) {
54+ return element . _tolgee . wrappedWithElementOnlyKey ;
55+ }
3056 const keys = TranslationHighlighter . getKeyOptions ( element ) ;
3157 if ( keys . size > 1 ) {
3258 return await this . renderer . getKey ( { keys : keys , openEvent : mouseEvent } ) ;
@@ -38,15 +64,6 @@ export class TranslationHighlighter {
3864 console . error ( 'No key to translate. This seems like a bug in tolgee.' ) ;
3965 }
4066
41- private static getKeyOptions ( node : ElementWithMeta ) : Set < string > {
42- const nodes = Array . from ( node . _tolgee . nodes ) ;
43- const keys = nodes . reduce (
44- ( acc , curr ) => [ ...acc , ...curr . _tolgee . keys . map ( ( k ) => k . key ) ] ,
45- [ ]
46- ) ;
47- return new Set ( keys ) ;
48- }
49-
5067 private translationEdit = async ( e : MouseEvent , element : ElementWithMeta ) => {
5168 if ( typeof this . renderer === 'object' ) {
5269 const key = await this . getKey ( e , element ) ;
@@ -62,18 +79,4 @@ export class TranslationHighlighter {
6279 'To disable highlighting use production mode.'
6380 ) ;
6481 } ;
65-
66- private get renderer ( ) {
67- if ( this . _renderer === undefined ) {
68- if ( typeof this . properties . config . ui === 'function' ) {
69- this . _renderer = new this . properties . config . ui ( {
70- coreService : this . service ,
71- properties : this . properties ,
72- eventService : this . eventService ,
73- translationService : this . translationService ,
74- } ) ;
75- }
76- }
77- return this . _renderer ;
78- }
7982}
0 commit comments