@@ -39,6 +39,10 @@ export default class GleapTranslationManager {
39
39
}
40
40
41
41
static translateText ( key ) {
42
+ if ( ! key ) {
43
+ return "" ;
44
+ }
45
+
42
46
const instance = GleapTranslationManager . getInstance ( ) ;
43
47
44
48
var language = "en" ;
@@ -49,23 +53,33 @@ export default class GleapTranslationManager {
49
53
language = instance . overrideLanguage . toLowerCase ( ) ;
50
54
}
51
55
52
- var customTranslation = { } ;
53
- const translationKeys = Object . keys ( instance . customTranslation ) ;
54
- for ( var i = 0 ; i < translationKeys . length ; i ++ ) {
55
- const translationKey = translationKeys [ i ] ;
56
- if ( language && translationKey && language === translationKey . toLowerCase ( ) ) {
57
- if ( instance . customTranslation [ translationKey ] ) {
58
- customTranslation = instance . customTranslation [ translationKey ] ;
56
+ const searchForTranslationTable = ( langKey ) => {
57
+ var customTranslation = null ;
58
+ const translationKeys = Object . keys ( instance . customTranslation ) ;
59
+ for ( var i = 0 ; i < translationKeys . length ; i ++ ) {
60
+ const translationKey = translationKeys [ i ] ;
61
+ if ( langKey && translationKey && langKey === translationKey . toLowerCase ( ) ) {
62
+ if ( instance . customTranslation [ translationKey ] ) {
63
+ customTranslation = instance . customTranslation [ translationKey ] ;
64
+ }
59
65
}
60
66
}
61
- }
62
67
63
- if ( customTranslation [ key ] ) {
64
- return customTranslation [ key ] ;
68
+ return customTranslation ;
65
69
}
66
70
67
- if ( ! key ) {
68
- return "" ;
71
+ var customTranslation = searchForTranslationTable ( language ) ;
72
+
73
+ // Extended search for language match only.
74
+ if ( ! customTranslation && language ) {
75
+ const langKeys = language . split ( "-" ) ;
76
+ if ( langKeys && langKeys . length > 1 ) {
77
+ customTranslation = searchForTranslationTable ( langKeys [ 0 ] ) ;
78
+ }
79
+ }
80
+
81
+ if ( customTranslation && customTranslation [ key ] ) {
82
+ return customTranslation [ key ] ;
69
83
}
70
84
71
85
return key ;
0 commit comments