react-localize
Advanced tools
Comparing version 1.0.0-rc1 to 1.0.0-rc2
@@ -24,5 +24,6 @@ 'use strict'; | ||
var message = props.message; | ||
var children = props.children; | ||
var values = props.values; | ||
var rest = _objectWithoutProperties(props, ['message', 'values']); | ||
var rest = _objectWithoutProperties(props, ['message', 'children', 'values']); | ||
@@ -32,7 +33,17 @@ var localize = context.localize; | ||
return _react2.default.createElement( | ||
'span', | ||
rest, | ||
localize.apply(undefined, [message].concat(_toConsumableArray(values))) | ||
); | ||
var localized = message; | ||
if (typeof localize === 'function') { | ||
localized = localize.apply(undefined, [message].concat(_toConsumableArray(values))); | ||
} | ||
if (typeof children === 'function') { | ||
return children.apply(undefined, [localized, message].concat(_toConsumableArray(values))); | ||
} else { | ||
return _react2.default.createElement( | ||
'span', | ||
rest, | ||
localized | ||
); | ||
} | ||
}; | ||
@@ -43,2 +54,3 @@ | ||
Text.propTypes = { | ||
children: func, | ||
message: string.isRequired, | ||
@@ -45,0 +57,0 @@ values: array |
{ | ||
"name": "react-localize", | ||
"version": "1.0.0-rc1", | ||
"version": "1.0.0-rc2", | ||
"description": "A simple context wrapper and text localization component for localizing strings", | ||
@@ -5,0 +5,0 @@ "main": "build/index.js", |
@@ -31,2 +31,15 @@ # react-localize | ||
## Also you can defer rendering for custom output: | ||
``` | ||
<Text message='some.key'> | ||
{(localized, message, ...values) => { | ||
// message & ...values are optional, and are really just whatever you sent in on props | ||
return <input type="text" placholder={localized} /> | ||
}} | ||
</Text> | ||
``` | ||
(that's so you can use something other than span, or put localized text in attributes, mostly) | ||
## More Stuff | ||
@@ -33,0 +46,0 @@ I think you might need to browserify `build/index.js` because of `util` dependency. I have the `dist/` folder but I'm not sure how I feel about all that or what it should do yet. |
@@ -19,6 +19,17 @@ /* | ||
const Text = (props, context) => { | ||
const { message, values, ...rest } = props; | ||
const { message, children, values, ...rest } = props; | ||
const { localize } = context; | ||
return (<span {...rest}>{localize(message, ...values)}</span>); | ||
let localized = message; | ||
if (typeof localize === 'function') { | ||
localized = localize(message, ...values); | ||
} | ||
// allow for optional alternative API using render-prop pattern | ||
if (typeof children === 'function') { | ||
return children(localized, message, ...values); | ||
} else { | ||
return (<span {...rest}>{localized}</span>); | ||
} | ||
}; | ||
@@ -29,2 +40,3 @@ | ||
Text.propTypes = { | ||
children: func, | ||
message: string.isRequired, | ||
@@ -31,0 +43,0 @@ values: array |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
671661
17056
48
0