@@ -8,6 +8,7 @@ function messageSetup(componentProps, instance, args) {
88 var defaultMessage , path ;
99 var children = componentProps . children ;
1010 var scope = componentProps . scope ;
11+ var pathProperty = componentProps . path ;
1112
1213 function extractFromFnComments ( fn ) {
1314 return fn . toString ( ) . replace ( / ( f u n c t i o n \( \) \{ \/ \* | \* \/ \} ) / g, "" ) ;
@@ -46,9 +47,9 @@ function messageSetup(componentProps, instance, args) {
4647 Globalize . loadMessages ( data ) ;
4748 }
4849
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 ( "/" ) ;
5253 } else {
5354 defaultMessage = getDefaultMessage ( children ) ;
5455 args [ 0 ] = sanitizePath ( defaultMessage ) ;
@@ -158,12 +159,24 @@ Globalize.messageFormatter =
158159Globalize . prototype . messageFormatter = function ( pathOrMessage ) {
159160 var aux = { } ;
160161 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 ) ;
165177 }
166- arguments [ 0 ] = sanitizedPath ;
178+
179+ arguments [ 0 ] = sanitizedPathExists ? sanitizedPath : pathOrMessage ;
167180 return messageFormatterSuper . apply ( this , arguments ) ;
168181} ;
169182
0 commit comments