@@ -72,59 +72,90 @@ var abp = abp || {};
72
72
/* LOCALIZATION ***********************************************/
73
73
74
74
abp . localization = abp . localization || { } ;
75
-
75
+ abp . localization . internal = abp . localization . internal || { } ;
76
76
abp . localization . values = abp . localization . values || { } ;
77
-
78
- abp . localization . localize = function ( key , sourceName ) {
79
- if ( sourceName === '_' ) { //A convention to suppress the localization
80
- return key ;
77
+ abp . localization . resources = abp . localization . resources || { } ;
78
+
79
+ abp . localization . internal . getResource = function ( resourceName ) {
80
+ var resource = abp . localization . resources [ resourceName ] ;
81
+ if ( resource ) {
82
+ return resource ;
83
+ }
84
+
85
+ var legacySource = abp . localization . values [ resourceName ] ;
86
+ if ( legacySource ) {
87
+ return {
88
+ texts : abp . localization . values [ resourceName ] ,
89
+ baseResources : [ ]
90
+ } ;
81
91
}
82
-
83
- sourceName = sourceName || abp . localization . defaultResourceName ;
84
- if ( ! sourceName ) {
85
- abp . log . warn ( 'Localization source name is not specified and the defaultResourceName was not defined!' ) ;
86
- return key ;
92
+
93
+ abp . log . warn ( 'Could not find localization source: ' + resourceName ) ;
94
+ return null ;
95
+ } ;
96
+
97
+ abp . localization . internal . localize = function ( key , sourceName ) {
98
+ var resource = abp . localization . internal . getResource ( sourceName ) ;
99
+ if ( ! resource ) {
100
+ return {
101
+ value : key ,
102
+ found : false
103
+ } ;
87
104
}
88
105
89
- var source = abp . localization . values [ sourceName ] ;
90
- if ( ! source ) {
91
- abp . log . warn ( 'Could not find localization source: ' + sourceName ) ;
92
- return key ;
93
- }
106
+ var value = resource . texts [ key ] ;
107
+ if ( value === undefined ) {
108
+ for ( var i = 0 ; i < resource . baseResources . length ; i ++ ) {
109
+ var basedArguments = Array . prototype . slice . call ( arguments , 0 ) ;
110
+ basedArguments [ 1 ] = resource . baseResources [ i ] ;
94
111
95
- var value = source [ key ] ;
96
- if ( value == undefined ) {
97
- return key ;
112
+ var result = abp . localization . internal . localize . apply ( this , basedArguments ) ;
113
+ if ( result . found ) {
114
+ return result ;
115
+ }
116
+ }
117
+
118
+ return {
119
+ value : key ,
120
+ found : false
121
+ } ;
98
122
}
99
123
100
124
var copiedArguments = Array . prototype . slice . call ( arguments , 0 ) ;
101
125
copiedArguments . splice ( 1 , 1 ) ;
102
126
copiedArguments [ 0 ] = value ;
103
127
104
- return abp . utils . formatString . apply ( this , copiedArguments ) ;
128
+ return {
129
+ value : abp . utils . formatString . apply ( this , copiedArguments ) ,
130
+ found : true
131
+ } ;
105
132
} ;
106
133
107
- abp . localization . isLocalized = function ( key , sourceName ) {
134
+ abp . localization . localize = function ( key , sourceName ) {
108
135
if ( sourceName === '_' ) { //A convention to suppress the localization
109
- return true ;
136
+ return key ;
110
137
}
111
138
112
139
sourceName = sourceName || abp . localization . defaultResourceName ;
113
140
if ( ! sourceName ) {
114
- return false ;
141
+ abp . log . warn ( 'Localization source name is not specified and the defaultResourceName was not defined!' ) ;
142
+ return key ;
115
143
}
116
144
117
- var source = abp . localization . values [ sourceName ] ;
118
- if ( ! source ) {
119
- return false ;
145
+ return abp . localization . internal . localize . apply ( this , arguments ) . value ;
146
+ } ;
147
+
148
+ abp . localization . isLocalized = function ( key , sourceName ) {
149
+ if ( sourceName === '_' ) { //A convention to suppress the localization
150
+ return true ;
120
151
}
121
152
122
- var value = source [ key ] ;
123
- if ( value === undefined ) {
153
+ sourceName = sourceName || abp . localization . defaultResourceName ;
154
+ if ( ! sourceName ) {
124
155
return false ;
125
156
}
126
157
127
- return true ;
158
+ return abp . localization . internal . localize ( key , sourceName ) . found ;
128
159
} ;
129
160
130
161
abp . localization . getResource = function ( name ) {
@@ -173,12 +204,10 @@ var abp = abp || {};
173
204
174
205
abp . auth = abp . auth || { } ;
175
206
176
- abp . auth . policies = abp . auth . policies || { } ;
177
-
178
207
abp . auth . grantedPolicies = abp . auth . grantedPolicies || { } ;
179
208
180
209
abp . auth . isGranted = function ( policyName ) {
181
- return abp . auth . policies [ policyName ] != undefined && abp . auth . grantedPolicies [ policyName ] != undefined ;
210
+ return abp . auth . grantedPolicies [ policyName ] != undefined ;
182
211
} ;
183
212
184
213
abp . auth . isAnyGranted = function ( ) {
@@ -687,7 +716,7 @@ var abp = abp || {};
687
716
}
688
717
689
718
/**
690
- * Escape HTML to help prevent XSS attacks.
719
+ * Escape HTML to help prevent XSS attacks.
691
720
*/
692
721
abp . utils . htmlEscape = function ( html ) {
693
722
return typeof html === 'string' ? html . replace ( / & / g, '&' ) . replace ( / < / g, '<' ) . replace ( / > / g, '>' ) . replace ( / " / g, '"' ) : html ;
@@ -759,7 +788,7 @@ var abp = abp || {};
759
788
return toUtc ( date ) ;
760
789
}
761
790
} ;
762
-
791
+
763
792
/* FEATURES *************************************************/
764
793
765
794
abp . features = abp . features || { } ;
@@ -774,7 +803,7 @@ var abp = abp || {};
774
803
abp . features . get = function ( name ) {
775
804
return abp . features . values [ name ] ;
776
805
} ;
777
-
806
+
778
807
/* GLOBAL FEATURES *************************************************/
779
808
780
809
abp . globalFeatures = abp . globalFeatures || { } ;
0 commit comments