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
Bringing the i18n functionality of Globalize, backed by CLDR, to React
React components that provide internationalization features via Globalize. With a little initialization, you get instantly internationalized values in your application.
npm install react-globalize --save
In your application just:
var ReactGlobalize = require("react-globalize");
var Globalize = require("globalize");
var FormatCurrency = ReactGlobalize.FormatCurrency;
// Initialize Globalize and load your CLDR data
// See https://github.com/jquery/globalize for details on Globalize usage
Globalize.locale("en");
// Then, to use any ReactGlobalize component (with JSX)
React.render(
<FormatCurrency currency="USD">{150}</FormatCurrency>
);
// Which would render for example:
// <span>$150.00</span> when using the `en` (English) locale, or
// <span>150,00 $</span> when using the `de` (German) locale, or
// <span>US$150,00</span> when using the `pt` (Portuguese) locale, or
// <span>US$ 150.00</span> when using the `zh` (Chinese) locale, or
// <span>US$ ١٥٠٫٠٠</span> when using the `ar` (Arabic) locale.
Further info about each component is available below.
These components 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 component has a set of props, both required and optional. The component then uses the values of those props to properly format the passed values. Below is a listing of each component, its props and a usage example.
It allows to format a currency. Your code can be completely independent of the locale conventions for which currency symbol to use, whether or not there's a space between the currency symbol and the value, the side where the currency symbol must be placed, or even decimal digits used by particular currencies. Currencies can be displayed using symbols (the default), accounting form, 3-letter code, or plural messages. See currencyFormatter docs in Globalize for more information.
The numeric value to be formatted. Required.
Globalize.locale(locale)
when formatting the amount.Default format with USD.
<FormatCurrency currency="USD">{150}</FormatCurrency>
// Which would render:
// <span>$150.00</span> when using the `en` (English) locale, or
// <span>US$150,00</span> when using the `pt` (Portuguese) locale.
Accounting format with EUR.
<FormatCurrency currency="EUR" options={{style: "accounting"}}>
{-150}
</FormatCurrency>
// Which would render:
// <span>(€150.00)</span> when using the `en` (English) locale, or
// <span>(€150,00)</span> when using the `pt` (Portuguese) locale.
It allows to convert dates and times from their internal representations to textual form in a language-independent manner. Your code can conveniently control the length of the formatted date, time, datetime. See dateFormatter docs in Globalize for more information.
The date object to be formatted. Required.
Globalize.locale(locale)
when formatting the amount.Simple string skeleton.
<FormatDate options={{skeleton: "GyMMMd"}}>
{new Date()}
</FormatDate>
// Which would render:
// <span>Feb 27, 2015 AD</span> when using the `en` (English) locale, or
// <span>27 de fev de 2015 d.C.</span> when using the `pt` (Portuguese) locale.
Medium length date and time.
<FormatDate options={{datetime: "medium"}}>
{new Date()}
</FormatDate>
// Which would render:
// <span>Feb 27, 2015, 11:17:10 AM</span> when using the `en` (English) locale, or
// <span>27 de fev de 2015 11:17:10</span> when using the `pt` (Portuguese) locale.
It allows for the creation of internationalized messages (as defined by the ICU Message syntax), with optional arguments (variables/placeholders) allowing for simple replacement, gender and plural inflections. The arguments can occur in any order, which is necessary for translation into languages with different grammars. See messageFormatter docs in Globalize for more information.
Required unless the path
property is set. It's a string with the default message. Either this or the path
property is required.
Globalize.locale(locale)
when formatting the amount.Below translation message JSON used in these examples:
{
"pt": {
"Hi": "Oi",
"Hi, {0} {1} {2}": "Olá, {0} {1} {2}",
"Hello, {first} {middle} {last}": "Ei, {first} {middle} {last}"
}
}
Simple salutation.
<FormatMessage>Hi</FormatMessage>
// Which would render:
// <span>Hi</span> when using the default message, in this case `en` (English).
// <span>Oi</span> when using the `pt` (Portuguese) locale and its translation messages.
Variable Replacement.
// Using Array.
<FormatMessage variables={["Wolfgang", "Amadeus", "Mozart"]}>
{"Hi, {0} {1} {2}"}
</FormatMessage>
// Which would render:
// <span>Hello, Wolfgang Amadeus Mozart</span> when using the default message, in this case `en` (English).
// <span>Hello, Wolfgang Amadeus Mozart</span> when using the `en` (English) locale and its translation messages.
// Using Object.
<FormatMessage variables={{first:"Wolfgang", middle:"Amadeus", last:"Mozart"}}>
{"Hey, {first} {middle} {last}"}
</FormatMessage>
// Which would render:
// <span>Hey, Wolfgang Amadeus Mozart</span> when using the default message, in this case `en` (English).
// <span>Ei, Wolfgang Amadeus Mozart</span> when using the `pt` (Portuguese) locale and its translation messages.
Element Replacement.
<FormatMessage
elements={{
reactGlobalizeLink: <a href='https://github.com/jquery-support/react-globalize'></a>
}}
>
For more information, see [reactGlobalize]React Globalize[/reactGlobalize]
</FormatMessage>
// Which would render:
// <span>
// For more information, see
// <a href="https://github.com/jquery-support/react-globalize">React Globalize</a>
// </span>
// when using the default message, in this case `en` (English).
See messageFormatter docs in Globalize for more message examples (e.g., pluralization or gender selection).
It allows to convert numbers into textual representations. Your code can be completely independent of the locale conventions for decimal points, thousands-separators, or even the particular decimal digits used, or whether the number format is even decimal. Though, it can still conveniently control various aspects of the formatted number like the minimum and maximum fraction digits, integer padding, rounding method, display as percentage, and others. See numberFormatter docs in Globalize for more information.
The number to be formatted. Required.
Globalize.locale(locale)
when formatting the amount.Default format pi.
<FormatNumber locale="en">{Math.PI}</FormatNumber>
// Which would render:
// <span>3.142</span> when using the `en` (English) locale, or
// <span>3,142</span> when using the `pt` (Portuguese) locale.
Show at least 2 decimal places.
<FormatNumber options={{minimumFractionDigits: 2}}>
{10000}
</FormatNumber>
// Which would render:
// <span>10,000.00</span> when using the `en` (English) locale, or
// <span>10.000,00</span> when using the `pt` (Portuguese) locale.
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.