1- import { GleapFrameManager , GleapFeedbackButtonManager , GleapSession } from "./Gleap" ;
1+ import { GleapFrameManager , GleapFeedbackButtonManager , GleapSession , GleapConfigManager } from "./Gleap" ;
22
33export default class GleapTranslationManager {
4- customTranslation = { } ;
54 overrideLanguage = "" ;
65 isRTLLayout = false ;
76
@@ -28,26 +27,21 @@ export default class GleapTranslationManager {
2827 */
2928 setOverrideLanguage ( language ) {
3029 this . overrideLanguage = language ;
31-
32- //GleapFrameManager.getInstance().sendConfigUpdate();
33- //this.updateRTLSupport();
3430 }
3531
3632 updateRTLSupport ( ) {
3733 // Update RTL support.
38- this . isRTLLayout = GleapTranslationManager . translateText ( "rtlLang" ) === "true" ;
34+ const flowConfig = GleapConfigManager . getInstance ( ) . getFlowConfig ( ) ;
35+
36+ this . isRTLLayout = false ;
37+ if ( flowConfig && flowConfig . localizationOptions && flowConfig . localizationOptions . rtl ) {
38+ this . isRTLLayout = true ;
39+ }
40+
3941 GleapFeedbackButtonManager . getInstance ( ) . updateFeedbackButtonState ( ) ;
4042 GleapFrameManager . getInstance ( ) . updateFrameStyle ( ) ;
4143 }
42-
43- /**
44- * Sets the custom translations.
45- * @param {* } customTranslation
46- */
47- setCustomTranslation ( customTranslation ) {
48- this . customTranslation = customTranslation ;
49- }
50-
44+
5145 getActiveLanguage ( ) {
5246 var language = "en" ;
5347 if ( typeof navigator !== "undefined" ) {
@@ -61,43 +55,15 @@ export default class GleapTranslationManager {
6155 }
6256
6357 static translateText ( key ) {
64- return key ;
65-
6658 if ( ! key ) {
6759 return "" ;
6860 }
6961
70- const instance = GleapTranslationManager . getInstance ( ) ;
71-
72- var language = instance . getActiveLanguage ( ) ;
73-
74- const searchForTranslationTable = ( langKey ) => {
75- var customTranslation = null ;
76- const translationKeys = Object . keys ( instance . customTranslation ) ;
77- for ( var i = 0 ; i < translationKeys . length ; i ++ ) {
78- const translationKey = translationKeys [ i ] ;
79- if ( langKey && translationKey && langKey === translationKey . toLowerCase ( ) ) {
80- if ( instance . customTranslation [ translationKey ] ) {
81- customTranslation = instance . customTranslation [ translationKey ] ;
82- }
83- }
84- }
85-
86- return customTranslation ;
87- }
88-
89- var customTranslation = searchForTranslationTable ( language ) ;
90-
91- // Extended search for language match only.
92- if ( ! customTranslation && language ) {
93- const langKeys = language . split ( "-" ) ;
94- if ( langKeys && langKeys . length > 1 ) {
95- customTranslation = searchForTranslationTable ( langKeys [ 0 ] ) ;
96- }
97- }
62+ const flowConfig = GleapConfigManager . getInstance ( ) . getFlowConfig ( ) ;
63+ const staticTranslation = flowConfig . staticTranslations ;
9864
99- if ( customTranslation && customTranslation [ key ] ) {
100- return customTranslation [ key ] ;
65+ if ( staticTranslation && staticTranslation [ key ] ) {
66+ return staticTranslation [ key ] ;
10167 }
10268
10369 return key ;
0 commit comments