Installations
npm install react-polyglot
Releases
Developer
nayaabkhan
Developer Guide
Module System
CommonJS
Min. Node Version
Typescript Support
Yes
Node Version
NPM Version
Statistics
56 Stars
96 Commits
15 Forks
3 Watching
16 Branches
8 Contributors
Updated on 16 Feb 2024
Languages
JavaScript (97.01%)
HTML (2.99%)
Total Downloads
Cumulative downloads
Total Downloads
7,168,200
Last day
88.2%
7,051
Compared to previous day
Last week
34.8%
28,531
Compared to previous week
Last month
48.1%
95,668
Compared to previous month
Last year
-13.6%
876,035
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
2
Peer Dependencies
2
React Polyglot
Provides higher order component for using Polyglot with React
Installation
npm install --save react-polyglot
Usage
react-polyglot
exports consists for one wrapper component called I18n
, one decorator called
translate
and one hook called useTranslate
. The decorator provides a prop t
which is instance of Polyglot
.
You are required to wrap your root component with I18n
and pass on a locale
like en
or fr
.
And messages
object containing the strings.
1import React from 'react'; 2import { render } from 'react-dom'; 3import { I18n } from 'react-polyglot'; 4import App from './components/app'; 5 6const locale = window.locale || 'en'; 7const messages = { 8 "hello_name": "Hello, %{name}.", 9 "num_cars": "%{smart_count} car |||| %{smart_count} cars", 10} 11 12render( 13 <I18n locale={locale} messages={messages}> 14 <App /> 15 </I18n>, 16 document.getElementById('app') 17);
Then inside App
or a child component of App
you can do:
1import React from 'react'; 2import { translate } from 'react-polyglot'; 3 4const Greeter = ({ name, t }) => ( 5 <h3>{t('hello_name', { name })}</h3> 6); 7 8Greeter.propTypes = { 9 name: React.PropTypes.string.isRequired, 10 t: React.PropTypes.func.isRequired, 11}; 12 13export default translate()(Greeter);
or with React Hooks:
1import React from 'react'; 2import { useTranslate } from 'react-polyglot'; 3 4export default const Greeter = ({ name }) => { 5 const t = useTranslate(); 6 7 return ( 8 <h3>{t('hello_name', { name })}</h3> 9 ); 10}; 11 12Greeter.propTypes = { 13 name: React.PropTypes.string.isRequired 14}; 15
Live Examples
Minimal example using class components
https://codesandbox.io/s/mq76ojk228
Advance example with user changeable locales
https://codesandbox.io/s/px8n63v0m
How to provide context in your tests
Use a simple helper to wrap your components in a context.
1export const wrapWithContext = function (component, context, contextTypes) { 2 const wrappedComponent = React.createClass({ 3 childContextTypes: contextTypes, 4 getChildContext() { 5 return context; 6 }, 7 render() { 8 return component; 9 }, 10 }); 11 return React.createElement(wrappedComponent); 12}
Then use it inside your tests.
1import React from 'react'; 2import { renderToString } from 'react-dom/server'; 3import Polyglot from 'node-polyglot'; 4import Greeter from './greeter'; 5import { wrapWithContext } from './helpers'; 6 7const polyglot = new Polyglot({ 8 locale: 'en', 9 phrases: {"hello_name": "Hello, %{name}."}, 10}); 11 12const greeterWithContext = wrapWithContext( 13 <Greeter name="Batsy" />, 14 { t: polyglot.t.bind(polyglot) }, 15 { t: React.PropTypes.func } 16); 17 18// use greeterWithContext in your tests 19// here it is shown how to use it with renderToString 20console.log(renderToString(greeterWithContext));
Release History
Check the Releases tab.
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
security policy file detected
Details
- Info: security policy file detected: SECURITY.md:1
- Warn: no linked content found
- Info: Found disclosure, vulnerability, and/or timelines in security policy: SECURITY.md:1
- Info: Found text in security policy: SECURITY.md:1
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 0/24 approved changesets -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/ci.yml:1
- Info: no jobLevel write permissions found
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:17: update your workflow using https://app.stepsecurity.io/secureworkflow/nayaabkhan/react-polyglot/ci.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:24: update your workflow using https://app.stepsecurity.io/secureworkflow/nayaabkhan/react-polyglot/ci.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:43: update your workflow using https://app.stepsecurity.io/secureworkflow/nayaabkhan/react-polyglot/ci.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:50: update your workflow using https://app.stepsecurity.io/secureworkflow/nayaabkhan/react-polyglot/ci.yml/master?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/ci.yml:69: update your workflow using https://app.stepsecurity.io/secureworkflow/nayaabkhan/react-polyglot/ci.yml/master?enable=pin
- Warn: downloadThenRun not pinned by hash: .github/workflows/ci.yml:82
- Info: 0 out of 4 GitHub-owned GitHubAction dependencies pinned
- Info: 0 out of 1 third-party GitHubAction dependencies pinned
- Info: 0 out of 1 downloadThenRun dependencies pinned
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
- Warn: branch protection not enabled for branch 'develop'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 8 are checked with a SAST tool
Reason
47 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92
- Warn: Project is vulnerable to: GHSA-6chw-6frg-f759
- Warn: Project is vulnerable to: GHSA-v88g-cgmw-v5xw
- Warn: Project is vulnerable to: GHSA-93q8-gq69-wqmw
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-x9w5-v3q2-3rhw
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-gxpj-cx7g-858c
- Warn: Project is vulnerable to: GHSA-w573-4hg7-7wgq
- Warn: Project is vulnerable to: GHSA-434g-2637-qmqr
- Warn: Project is vulnerable to: GHSA-49q7-c7j4-3p7m
- Warn: Project is vulnerable to: GHSA-977x-g7h5-7qgw
- Warn: Project is vulnerable to: GHSA-f7q4-pwc6-w24p
- Warn: Project is vulnerable to: GHSA-fc9h-whq2-v747
- Warn: Project is vulnerable to: GHSA-8r6j-v8pm-fqw3
- Warn: Project is vulnerable to: MAL-2023-462
- Warn: Project is vulnerable to: GHSA-ww39-953v-wcq6
- Warn: Project is vulnerable to: GHSA-43f8-2h32-f4cj
- Warn: Project is vulnerable to: GHSA-qqgx-2p2h-9c37
- Warn: Project is vulnerable to: GHSA-896r-f27r-55mw
- Warn: Project is vulnerable to: GHSA-9c47-m6qq-7p4h
- Warn: Project is vulnerable to: GHSA-6c8f-qphg-qjgp
- Warn: Project is vulnerable to: GHSA-76p3-8jx3-jpfq
- Warn: Project is vulnerable to: GHSA-3rfm-jhwj-7488
- Warn: Project is vulnerable to: GHSA-hhq3-ff78-jv3g
- Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv
- Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3
- Warn: Project is vulnerable to: GHSA-vh95-rmgr-6w4m / GHSA-xvch-5gv4-984h
- Warn: Project is vulnerable to: GHSA-5fw9-fq32-wv5p
- Warn: Project is vulnerable to: GHSA-hj48-42vr-x3v9
- Warn: Project is vulnerable to: GHSA-hrpp-h998-j3pp
- Warn: Project is vulnerable to: GHSA-p8p7-x288-28g6
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
- Warn: Project is vulnerable to: GHSA-h9rv-jmmf-4pgx
- Warn: Project is vulnerable to: GHSA-hxcc-f52p-wc94
- Warn: Project is vulnerable to: GHSA-3jfq-g458-7qm9
- Warn: Project is vulnerable to: GHSA-r628-mhmh-qjhw
- Warn: Project is vulnerable to: GHSA-9r2w-394v-53qc
- Warn: Project is vulnerable to: GHSA-5955-9wpr-37jh
- Warn: Project is vulnerable to: GHSA-qq89-hq3f-393p
- Warn: Project is vulnerable to: GHSA-f5x3-32g6-xq36
- Warn: Project is vulnerable to: GHSA-4wf5-vphf-c2xc
- Warn: Project is vulnerable to: GHSA-jgrx-mgxx-jf9v
- Warn: Project is vulnerable to: GHSA-72xf-g2v4-qvf3
- Warn: Project is vulnerable to: GHSA-6fc8-4gx4-v693
- Warn: Project is vulnerable to: GHSA-3h5v-q93c-6h6q
- Warn: Project is vulnerable to: GHSA-p9pc-299p-vxgp
Score
2.8
/10
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More