react-localization
Advanced tools
Comparing version 0.0.18 to 0.1.0
@@ -218,3 +218,3 @@ 'use strict'; | ||
return isReactComponent(valueForPlaceholder) ? _react2.default.Children.toArray(valueForPlaceholder).map(function (component) { | ||
return _extends({}, component, { key: index }); | ||
return _extends({}, component, { key: index.toString() }); | ||
}) : valueForPlaceholder; | ||
@@ -221,0 +221,0 @@ } |
{ | ||
"name": "react-localization", | ||
"version": "0.0.18", | ||
"version": "0.1.0", | ||
"description": "Simple module to localize the React interface using the same syntax used in the ReactNativeLocalization module, use 'npm run build' before publishing", | ||
@@ -31,5 +31,5 @@ "scripts": { | ||
"babel-preset-es2015": "^6.22.0", | ||
"babel-preset-react": "^6.24.1", | ||
"babel-preset-stage-2": "^6.22.0", | ||
"jasmine": "^2.6.0", | ||
"jasmine-core": "^2.6.2" | ||
"jasmine": "^2.6.0" | ||
}, | ||
@@ -36,0 +36,0 @@ "dependencies": { |
@@ -0,1 +1,3 @@ | ||
import React from 'react'; | ||
import LocalizedStrings from '../src/LocalizedStrings'; | ||
@@ -135,2 +137,32 @@ | ||
}); | ||
describe('formatString with React components', () => { | ||
const reactStrings = new LocalizedStrings({ | ||
en: { | ||
onlyForMembers: "Only who have {0} can enter", | ||
onlyForMembersStrong: "Only who have {0} can {1}", | ||
helloThere: "Hello {0}! Are you sure {0} is your name?", | ||
}, | ||
fi: { | ||
onlyForMembers: "Vain {0} voivat tulla", | ||
onlyForMembersStrong: "Vain {0} voivat {1}", | ||
helloThere: "Moi {0}! Onko {0} varmasti nimesi?", | ||
} | ||
}); | ||
it('one React component', () => { | ||
expect(reactStrings.formatString(reactStrings.onlyForMembers, <a href="#">logged in</a>)) | ||
.toEqual(["Only who have ", [<a href="#" key="1">logged in</a>], " can enter"]); | ||
}); | ||
it('two React component', () => { | ||
expect(reactStrings.formatString(reactStrings.onlyForMembersStrong, <a href="#">logged in</a>, <b>enter</b>)) | ||
.toEqual(["Only who have ", [<a href="#" key="1">logged in</a>], " can ", [<b key="3">enter</b>]]); | ||
}); | ||
it('one React component twice in a string', () => { | ||
expect(reactStrings.formatString(reactStrings.helloThere, <i>Henrik</i>)) | ||
.toEqual(["Hello ", [<i key="1">Henrik</i>], "! Are you sure ", [<i key="3">Henrik</i>], " is your name?"]); | ||
}); | ||
}); | ||
}); |
@@ -149,3 +149,3 @@ 'use strict'; | ||
return isReactComponent(valueForPlaceholder) | ||
? React.Children.toArray(valueForPlaceholder).map(component => ({...component, key: index})) | ||
? React.Children.toArray(valueForPlaceholder).map(component => ({...component, key: index.toString()})) | ||
: valueForPlaceholder; | ||
@@ -152,0 +152,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
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
110543
2642
0