File tree Expand file tree Collapse file tree 2 files changed +25
-3
lines changed Expand file tree Collapse file tree 2 files changed +25
-3
lines changed Original file line number Diff line number Diff line change 1
1
var FormatMessage = require ( '../react-globalize' ) . FormatMessage ;
2
+ var FormatNumber = require ( '../react-globalize' ) . FormatNumber ;
2
3
var React = require ( 'react' ) ;
3
- var Globalize = require ( 'globalize' ) ;
4
4
5
5
module . exports = React . createClass ( {
6
6
getInitialState : function ( ) {
@@ -46,7 +46,10 @@ module.exports = React.createClass({
46
46
< br />
47
47
task count 0 - < FormatMessage locale = { this . state . locale } path = "task" variables = { { count : 0 } } />
48
48
< br />
49
- task count 1000 formatted - < FormatMessage ref = "formattedTask" locale = { this . state . locale } path = "task" variables = { { count : 1000 , formattedCount : Globalize ( this . state . locale ) . formatNumber ( 1000 ) } } />
49
+ task count 1000 formatted - < FormatMessage ref = "formattedTask" locale = { this . state . locale } path = "task" variables = { {
50
+ count : 1000 ,
51
+ formattedCount : < FormatNumber locale = { this . state . locale } value = { 1000 } />
52
+ } } />
50
53
< br />
51
54
like count 0 with offset:1 - < FormatMessage locale = { this . state . locale } path = "likeIncludingMe" variables = { { count : 0 } } />
52
55
< br />
Original file line number Diff line number Diff line change @@ -6,6 +6,25 @@ function capitalizeFirstLetter(string) {
6
6
return string . charAt ( 0 ) . toUpperCase ( ) + string . slice ( 1 ) ;
7
7
}
8
8
9
+ function isPlainObject ( value ) {
10
+ return value && typeof value === "object" &&
11
+ ! ( value . constructor &&
12
+ ! value . constructor . prototype . hasOwnProperty ( "isPrototypeOf" ) ) &&
13
+ ! React . isValidElement ( value ) ;
14
+ }
15
+
16
+ function supportReactElements ( value ) {
17
+ if ( isPlainObject ( value ) ) {
18
+ return Object . keys ( value ) . reduce ( function ( sum , i ) {
19
+ sum [ i ] = supportReactElements ( value [ i ] ) ;
20
+ return sum ;
21
+ } , { } ) ;
22
+ } else if ( React . isValidElement ( value ) ) {
23
+ value = new ReactGlobalize [ value . type . displayName ] ( value . _store . props ) . render ( ) . _store . props . children ;
24
+ }
25
+ return value ;
26
+ }
27
+
9
28
Object . getOwnPropertyNames ( Globalize ) . forEach ( function ( fn ) {
10
29
if ( fn . indexOf ( "format" ) === 0 ) {
11
30
var Fn = capitalizeFirstLetter ( fn ) ;
@@ -21,7 +40,7 @@ Object.getOwnPropertyNames(Globalize).forEach(function(fn) {
21
40
var instance = Globalize ;
22
41
var propArgs = argArray . map ( function ( element ) {
23
42
return componentProps [ element . replace ( / ( \s \/ \* | \* \/ ) / , "" ) . trim ( ) ] ;
24
- } ) ;
43
+ } ) . map ( supportReactElements ) ;
25
44
26
45
if ( componentProps [ "locale" ] ) {
27
46
instance = Globalize ( componentProps [ "locale" ] ) ;
You can’t perform that action at this time.
0 commit comments