@@ -8,6 +8,7 @@ function messageSetup(componentProps, instance, args) {
8
8
var defaultMessage , path ;
9
9
var children = componentProps . children ;
10
10
var scope = componentProps . scope ;
11
+ var pathProperty = componentProps . path ;
11
12
12
13
function extractFromFnComments ( fn ) {
13
14
return fn . toString ( ) . replace ( / ( f u n c t i o n \( \) \{ \/ \* | \* \/ \} ) / g, "" ) ;
@@ -46,9 +47,9 @@ function messageSetup(componentProps, instance, args) {
46
47
Globalize . loadMessages ( data ) ;
47
48
}
48
49
49
- // Set path.
50
- if ( args [ 0 ] ) {
51
- path = args [ 0 ] . split ( "/" ) ;
50
+ // Set path - path as props supercedes default value
51
+ if ( pathProperty ) {
52
+ path = pathProperty . split ( "/" ) ;
52
53
} else {
53
54
defaultMessage = getDefaultMessage ( children ) ;
54
55
args [ 0 ] = sanitizePath ( defaultMessage ) ;
@@ -158,12 +159,24 @@ Globalize.messageFormatter =
158
159
Globalize . prototype . messageFormatter = function ( pathOrMessage ) {
159
160
var aux = { } ;
160
161
var sanitizedPath = sanitizePath ( pathOrMessage ) ;
161
- if ( this . cldr && this . cldr . get ( [ "globalize-messages/{bundle}" , sanitizedPath ] ) === undefined ) {
162
- aux [ this . cldr . attributes . bundle ] = { } ;
163
- aux [ this . cldr . attributes . bundle ] [ sanitizedPath ] = pathOrMessage ;
164
- Globalize . loadMessages ( aux ) ;
162
+
163
+ /*
164
+ * want to distinguish between default value and path value - just checking
165
+ * for sanitizedPath won't be enough, because sanitizedPath !== pathOrMessage
166
+ * for strings like "salutations/hi"
167
+ */
168
+ var sanitizedPathExists = this . cldr &&
169
+ this . cldr . get ( [ "globalize-messages/{bundle}" , sanitizedPath ] ) !== undefined ;
170
+ var pathExists = this . cldr &&
171
+ this . cldr . get ( [ "globalize-messages/{bundle}" , pathOrMessage ] ) !== undefined ;
172
+
173
+ if ( ! sanitizedPathExists && ! pathExists ) {
174
+ aux [ this . cldr . attributes . bundle ] = { } ;
175
+ aux [ this . cldr . attributes . bundle ] [ sanitizedPath ] = pathOrMessage ;
176
+ Globalize . loadMessages ( aux ) ;
165
177
}
166
- arguments [ 0 ] = sanitizedPath ;
178
+
179
+ arguments [ 0 ] = sanitizedPathExists ? sanitizedPath : pathOrMessage ;
167
180
return messageFormatterSuper . apply ( this , arguments ) ;
168
181
} ;
169
182
0 commit comments