{"_id":"@5rabbits/react-polyglot","_rev":"7-b16be703d8a5cb027401b0ccfe3c1ec9","name":"@5rabbits/react-polyglot","dist-tags":{"latest":"0.2.6"},"versions":{"0.2.5":{"name":"@5rabbits/react-polyglot","version":"0.2.5","description":"Higher order React component for using Polyglot","main":"lib/index.js","files":["lib","src","example"],"publishConfig":{"access":"public"},"scripts":{"clean":"rimraf lib","build:example":"webpack example/app.js example/dist.js","build:commonjs":"babel src --out-dir lib","build":"npm run build:commonjs","prepublish":"npm run clean && npm run build"},"repository":{"type":"git","url":"git+https://github.com/nayaabkhan/react-polyglot.git"},"keywords":["react","airbnb","polyglot","i18n"],"author":{"name":"Nayaabkhan Khan","email":"khannayaab@gmail.com","url":"http://nayaabkhan.me"},"license":"MIT","bugs":{"url":"https://github.com/nayaabkhan/react-polyglot/issues"},"homepage":"https://github.com/nayaabkhan/react-polyglot#readme","peerDependencies":{"node-polyglot":"^2.0.0","react":"^0.14.0 || ^15.0.0-0"},"devDependencies":{"babel-cli":"^6.18.0","babel-core":"^6.11.4","babel-loader":"^6.2.4","babel-preset-es2015":"^6.9.0","babel-preset-react":"^6.11.1","react-dom":"^15.2.1","rimraf":"^2.5.4","webpack":"^1.13.1"},"dependencies":{"prop-types":"^15.5.8"},"licenseText":"The MIT License (MIT)\n\nCopyright (c) 2016 Nayaabkhan Khan\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n","_id":"@5rabbits/react-polyglot@0.2.5","dist":{"shasum":"6671cebfd4e54bec37d946d15a3619ff13e619a4","tarball":"https://registry.npmjs.org/@5rabbits/react-polyglot/-/react-polyglot-0.2.5.tgz","fileCount":17,"unpackedSize":753398,"integrity":"sha512-E+p23yoLnNxFZwD802Wy7DdTL9xBdOAC5qQ08jk2aFhuDAuvjWGnlwarWYbXRbhOTf1b60CFpUFXOo/r0HQGNw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIE/QvPNyqbaBEkY7/GyFLgjkNSrxbrViLMX8lb+APRTtAiEA06yr/u7DlizFCKH9IgoisuuXNwBJJ9N7JeYKxK3m7o8="}]},"maintainers":[{"name":"lemontech","email":"5rabbits@lemontech.com"},{"name":"rdiaz","email":"rdiazv89@gmail.com"}],"_npmUser":{"name":"rdiaz","email":"rdiazv89@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/react-polyglot_0.2.5_1523560531648_0.912886086704837"},"_hasShrinkwrap":false},"0.2.6":{"name":"@5rabbits/react-polyglot","version":"0.2.6","description":"Higher order React component for using Polyglot","main":"lib/index.js","files":["lib","src","example"],"publishConfig":{"access":"public"},"scripts":{"clean":"rimraf lib","build:example":"webpack example/app.js example/dist.js","build:commonjs":"babel src --out-dir lib","build":"npm run build:commonjs","prepublish":"npm run clean && npm run build"},"repository":{"type":"git","url":"git+https://github.com/nayaabkhan/react-polyglot.git"},"keywords":["react","airbnb","polyglot","i18n"],"author":{"name":"Nayaabkhan Khan","email":"khannayaab@gmail.com","url":"http://nayaabkhan.me"},"license":"MIT","bugs":{"url":"https://github.com/nayaabkhan/react-polyglot/issues"},"homepage":"https://github.com/nayaabkhan/react-polyglot#readme","peerDependencies":{"node-polyglot":"^2.0.0","react":"^0.14.0 || ^15.0.0-0 || ^16.0.0"},"devDependencies":{"babel-cli":"^6.18.0","babel-core":"^6.11.4","babel-loader":"^6.2.4","babel-preset-es2015":"^6.9.0","babel-preset-react":"^6.11.1","react-dom":"^15.2.1","rimraf":"^2.5.4","webpack":"^1.13.1"},"dependencies":{"prop-types":"^15.5.8"},"licenseText":"The MIT License (MIT)\n\nCopyright (c) 2016 Nayaabkhan Khan\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n","_id":"@5rabbits/react-polyglot@0.2.6","dist":{"shasum":"822af7267ff545d4e0a8ca180e1fd937c2bb7f11","tarball":"https://registry.npmjs.org/@5rabbits/react-polyglot/-/react-polyglot-0.2.6.tgz","fileCount":17,"unpackedSize":753409,"integrity":"sha512-ZrIe9bWlHuXpPMuA33CQHTI9U92mZ4geq3LjszUGJS00gkGlGujMbJMHTHXdtDwpopvq3h8h3XkTlD+F9afENA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIFSui3sK/8zeqbVgehES/YyTqDkil+4zIv6YaCKJEX5yAiEAikkKyRu2KKmhgTZYfCsQASapWQcYpnpm+5bffWA9xw0="}]},"maintainers":[{"name":"lemontech","email":"5rabbits@lemontech.com"},{"name":"rdiaz","email":"rdiazv89@gmail.com"}],"_npmUser":{"name":"rdiaz","email":"rdiazv89@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/react-polyglot_0.2.6_1523562155999_0.8678451501691895"},"_hasShrinkwrap":false}},"time":{"created":"2018-04-12T19:15:31.566Z","0.2.5":"2018-04-12T19:15:32.347Z","modified":"2022-06-12T14:11:48.562Z","0.2.6":"2018-04-12T19:42:36.103Z"},"maintainers":[{"email":"infra@lemontech.com","name":"lemonlet"},{"email":"glara@glara.cl","name":"glara"},{"email":"rdiazv89@gmail.com","name":"rdiaz"}],"description":"Higher order React component for using Polyglot","homepage":"https://github.com/nayaabkhan/react-polyglot#readme","keywords":["react","airbnb","polyglot","i18n"],"repository":{"type":"git","url":"git+https://github.com/nayaabkhan/react-polyglot.git"},"author":{"name":"Nayaabkhan Khan","email":"khannayaab@gmail.com","url":"http://nayaabkhan.me"},"bugs":{"url":"https://github.com/nayaabkhan/react-polyglot/issues"},"license":"MIT","readme":"# React Polyglot\nProvides higher order component for using Polyglot with React\n\n## Installation\n\n```\nnpm install --save react-polyglot\n```\n\n## Usage\n\n`react-polyglot` exports consists for one wrapper component called `I18n` and one decorator called\n`translate`. The decorator provides a prop `t` which is instance of `Polyglot`.\n\nYou are required to wrap your root component with `I18n` and pass on a `locale` like `en` or `fr`.\nAnd `messages` object containing the strings.\n\n```js\nimport React from 'react';\nimport { render } from 'react-dom';\nimport { I18n } from 'react-polyglot';\nimport App from './components/app';\n\nconst locale = window.locale || 'en';\nconst messages = {\n  \"hello_name\": \"Hello, %{name}.\",\n  \"num_cars\": \"%{smart_count} car |||| %{smart_count} cars\",\n}\n\nrender(\n  <I18n locale={locale} messages={messages}>\n    <App />\n  </I18n>,\n  document.getElementById('app')\n);\n```\n\nThen inside `App` or a child component of `App` you can do:\n\n```js\nimport React from 'react';\nimport { translate } from 'react-polyglot';\n\nconst Greeter = ({ name, t }) => (\n  <h3>{t('hello_name', { name })}</h3>\n);\n\nGreeter.propTypes = {\n  name: React.PropTypes.string.isRequired,\n  t: React.PropTypes.func.isRequired,\n};\n\nexport default translate()(Greeter);\n```\n\n## How to provide context in your tests\n\nUse a simple helper to wrap your components in a context.\n\n```js\nexport const wrapWithContext = function (component, context, contextTypes) {\n  const wrappedComponent = React.createClass({\n    childContextTypes: contextTypes,\n    getChildContext() {\n      return context;\n    },\n    render() {\n      return component;\n    },\n  });\n  return React.createElement(wrappedComponent);\n}\n```\n\nThen use it inside your tests.\n\n```js\nimport React from 'react';\nimport { renderToString } from 'react-dom/server';\nimport Polyglot from 'node-polyglot';\nimport Greeter from './greeter';\nimport { wrapWithContext } from './helpers';\n\nconst polyglot = new Polyglot({\n  locale: 'en',\n  phrases: {\"hello_name\": \"Hello, %{name}.\"},\n});\n\nconst greeterWithContext = wrapWithContext(\n  <Greeter name=\"Batsy\" />,\n  { t: polyglot.t.bind(polyglot) },\n  { t: React.PropTypes.func }\n);\n\n// use greeterWithContext in your tests\n// here it is shown how to use it with renderToString\nconsole.log(renderToString(greeterWithContext));\n```\n\n## Work in progress\n\nTests and Contributing guides are in progress.\n\n\n## Release History\n\n* 0.1.0 Initial Release\n* 0.2.0 Update the I18n component when the locale changes\n* 0.2.1 Add 'files' to keep in the package\n* 0.2.2 Add babel-cli for the commonjs build\n* 0.2.3 Add prop-types and start using that instead of React.PropTypes [PR#6](https://github.com/nayaabkhan/react-polyglot/pull/6)\n","readmeFilename":"README.md"}