Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
react-globalize
Advanced tools
Easy to use React mixins that provide internationalization features to any React component via Globalize. With a little initialization, you get instantly internationalized values in your components.
npm install react-globalize
In your application just:
var ReactGlobalize = require('react-globalize');
var Globalize = require('globalize');
// Initialize Globalize and load your CLDR data
// See https://github.com/jquery/globalize for details on Globalize usage
// In your component, this example just places the formatted value in a span
var CurrencyComponent = React.createClass({
mixins: [ReactGlobalize.formatCurrency],
...
render: function() {
return (
<span>{this.state.formattedValue}</span>
);
}
});
// Then to use your currency component (with JSX)
React.render(
<CurrencyComponent locale="en" currency="USD" value={150}/>
);
// Which would render <span>$150.00</span>
Further info about each mixin and its available props below
These mixins provide a simple way to display things like currency, dates, numbers and messages, formatted or translated to the current locale set by your application. Each mixin has a set of props, both required and optional, to be included in your component. The mixin then uses the values of those props, to add a formattedValue
to your component's state. Below is a listing of each mixin, its props and a usage example.
Default format with USD in English
<FormatCurrency locale="en" currency="USD" value={150} />
Result: this.state.formattedValue = $150.00
Accounting format with EUR in Portuguese
<FormatCurrency locale="pt-BR" currency="EUR" value={-150} options={{ style: "accounting" }} />
Result: this.state.formattedValue = (€150,00)
Simple string skeleton in English
<FormatDate locale="en" value={new Date()} pattern="GyMMMd" />
Result: this.state.formattedValue = Feb 27, 2015 AD
Medium length date and time in Portuguese
<FormatDate locale="pt-BR" value={new Date()} pattern={{ datetime: 'medium' }} />
Result: this.state.formattedValue = 27 de fev de 2015 11:17:10
Below message JSON used in these examples:
{
en: {
salutations: {
hi: "Hi",
bye: "Bye"
},
variables: {
hello: "Hello, {0} {1} {2}",
hey: "Hey, {first} {middle} {last}"
}
},
"pt-BR": {
salutations: {
hi: "Oi",
bye: "Tchau"
},
variables: {
hello: "Olá, {0} {1} {2}",
hey: "Ei, {first} {middle} {last}"
}
}
}
Hi in English: <FormatMessage locale="en" path="salutations/hi" />
Result: this.state.formattedValue = Hi
Hi in Portuguese: <FormatMessage locale="pt-BR" path="salutations/hi" />
Result: this.state.formattedValue = Oi
Array in English: <FormatMessage locale="en" path="variables/hello" variables={["Wolfgang", "Amadeus", "Mozart"]} />
Result: this.state.formattedValue = Hello, Wolfgang Amadeus Mozart
Object in Portuguese: <FormatMessage locale="pt-BR" path="variables/hey" variables={{first:"Wolfgang", middle:"Amadeus", last:"Mozart"}} />
Result: this.state.formattedValue = Ei, Wolfgang Amadeus Mozart
Default format pi in English
<FormatNumber locale="en" value={Math.PI} />
Result: this.state.formattedValue = 3.142
Show at least 2 decimal places in Portuguese
<FormatNumber locale="pt-BR" value={10000} options={{ minimumFractionDigits: 2 }} />
Result: this.state.formattedValue = 10.000,00
This project is distributed under the MIT license.
FAQs
Bringing the i18n functionality of Globalize, backed by CLDR, to React
The npm package react-globalize receives a total of 822 weekly downloads. As such, react-globalize popularity was classified as not popular.
We found that react-globalize demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.