lingui-react
Advanced tools
Comparing version 0.4.0 to 0.5.0
@@ -12,21 +12,10 @@ 'use strict'; | ||
// match <0>paired</0> and <1/> unpaired tags | ||
var tagRe = /<(\d+)>(.*)<\/\1>|<(\d+)\/>/; | ||
/** | ||
* `formatElements` - parse string and return tree of react elements | ||
* | ||
* `value` is string to be formatted with <0>Paired<0/> or <0/> (unpaired) | ||
* placeholders. `elements` is a array of react elements which indexes | ||
* correspond to element indexes in formatted string | ||
*/ | ||
function formatElements(value) { | ||
var elements = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : []; | ||
// TODO: warn if there're any unprocessed elements | ||
// TODO: warn if element at `index` doesn't exist | ||
var parts = value.split(tagRe); | ||
// no inline elements, return | ||
if (parts.length === 1) return value; | ||
@@ -45,11 +34,12 @@ | ||
for (var _iterator = getElements(parts)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { | ||
var _step$value = _slicedToArray(_step.value, 3), | ||
index = _step$value[0], | ||
children = _step$value[1], | ||
after = _step$value[2]; | ||
var _ref = _step.value; | ||
tree.push((0, _react.cloneElement)(elements[index], { key: index }, | ||
// unpaired tag shouldn't receive children (return null instead) | ||
children ? formatElements(children, elements) : null)); | ||
var _ref2 = _slicedToArray(_ref, 3); | ||
var index = _ref2[0]; | ||
var children = _ref2[1]; | ||
var after = _ref2[2]; | ||
tree.push((0, _react.cloneElement)(elements[index], { key: index }, children ? formatElements(children, elements) : null)); | ||
if (after) tree.push(after); | ||
@@ -75,16 +65,2 @@ } | ||
/* | ||
* `getElements` - return array of element indexes and element childrens | ||
* | ||
* `parts` is array of [pairedIndex, children, unpairedIndex, textAfter, ...] | ||
* where: | ||
* - `pairedIndex` is index of paired element (undef for unpaired) | ||
* - `children` are children of paired element (undef for unpaired) | ||
* - `unpairedIndex` is index of unpaired element (undef for paired) | ||
* - `textAfter` is string after all elements (empty string, if there's nothing) | ||
* | ||
* `parts` length is always multiply of 4 | ||
* | ||
* Returns: Array<[elementIndex, children, after]> | ||
*/ | ||
function getElements(parts) { | ||
@@ -91,0 +67,0 @@ if (!parts.length) return []; |
@@ -24,6 +24,2 @@ 'use strict'; | ||
/* | ||
* I18nManager - Connects to lingui-i18n/I18n class | ||
* Allows listeners to subscribe for changes | ||
*/ | ||
var I18nManager = function I18nManager(language, messages, i18n) { | ||
@@ -92,3 +88,3 @@ _classCallCheck(this, I18nManager); | ||
if (language !== prevProps.language || messages !== prevProps.messages) { | ||
this.i18nManager.update({ language: language, messages: messages }); | ||
this.i18nManager.update({ language, messages }); | ||
} | ||
@@ -95,0 +91,0 @@ } |
@@ -49,3 +49,3 @@ 'use strict'; | ||
var form = _plurals2.default[language].cardinal(n); | ||
var translation = this.props['_' + value] || this.props[form]; | ||
var translation = this.props[`_${value}`] || this.props[form]; | ||
@@ -52,0 +52,0 @@ return _react2.default.createElement( |
@@ -50,3 +50,3 @@ 'use strict'; | ||
var form = ordinalRules ? ordinalRules(n) : 'other'; | ||
var translation = this.props['_' + n] || this.props[form]; | ||
var translation = this.props[`_${n}`] || this.props[form]; | ||
@@ -53,0 +53,0 @@ return _react2.default.createElement( |
@@ -39,3 +39,3 @@ 'use strict'; | ||
language: props.i18n.language, | ||
translation: translation | ||
translation | ||
}; | ||
@@ -42,0 +42,0 @@ return _this; |
@@ -80,5 +80,3 @@ 'use strict'; | ||
i18n = _getI18n3.i18n; | ||
// $FlowIgnore: https://github.com/facebook/flow/issues/3241 | ||
return _react2.default.createElement(WrappedComponent, _extends({}, this.props, { i18n: i18n })); | ||
@@ -85,0 +83,0 @@ } |
{ | ||
"name": "lingui-react", | ||
"version": "0.4.0", | ||
"version": "0.5.0", | ||
"description": "React components for translations", | ||
@@ -33,8 +33,11 @@ "main": "lib/index.js", | ||
"lingui-formats": "^0.1.0", | ||
"lingui-i18n": "^0.3.0" | ||
"lingui-i18n": "^0.4.0" | ||
}, | ||
"devDependencies": { | ||
"babel-cli": "^6.23.0", | ||
"babel-plugin-transform-class-properties": "^6.23.0", | ||
"babel-plugin-transform-object-rest-spread": "^6.23.0", | ||
"babel-polyfill": "^6.23.0", | ||
"babel-preset-env": "^1.1.8", | ||
"babel-preset-react": "^6.23.0", | ||
"rimraf": "^2.5.4" | ||
@@ -47,3 +50,25 @@ }, | ||
"prepublish": "npm run clean && npm run build && npm run copy-flow" | ||
}, | ||
"engines": { | ||
"node": ">=4" | ||
}, | ||
"babel": { | ||
"presets": [ | ||
[ | ||
"env", | ||
{ | ||
"targets": { | ||
"node": 4 | ||
}, | ||
"useBuiltIns": true | ||
} | ||
], | ||
"react" | ||
], | ||
"plugins": [ | ||
"transform-class-properties", | ||
"transform-object-rest-spread" | ||
], | ||
"comments": false | ||
} | ||
} |
@@ -79,3 +79,4 @@ /* @flow */ | ||
style: 'currency', | ||
currency: 'EUR' | ||
currency: 'EUR', | ||
minimumFractionDigits: 2 | ||
}}} | ||
@@ -82,0 +83,0 @@ />) |
Sorry, the diff of this file is not supported yet
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
176339
7
2085
- Removedlingui-i18n@0.3.0(transitive)
- Removedmake-plural@4.3.0(transitive)
- Removedmessageformat-parser@1.1.0(transitive)
- Removedminimist@1.2.8(transitive)
Updatedlingui-i18n@^0.4.0