Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
i18n-polyglot
Advanced tools
A React wrapper for node-polyglot.
You need to use the <International />
wrapper around your app to create a node-polyglot instance and to provide context to your components.
import International from 'i18n-polyglot';
const locale = {
type: 'de',
dictionary: {
greeting: 'Hallo!',
},
// anything else locale related
};
<International locale={locale}>
<App />
</International>
<International />
component takes a locale
object prop with following:
type
: string, name of the locale, for possible values check here.dictionary
: object, same as phrases
object one would pass to node-polyglot.T
is a component that allows for JSX within your substitutions options. Use it when you need to use JSX or accessing t
function is inconvenient.
import { T } from 'i18n-polyglot';
const locale = {
dictionary: {
substitution: 'I have come here to chew %{variable_1} and kick %{variable_2}... and I\'m all out of %{variable_1}.',
},
};
const MyComponent = ({ t, locale }) => (
<T
id="substitution"
variable_1={<strong onClick={() => alert('🍬')}>bubblegum</strong>}
variable_2={<em onClick={() => alert('🍑')}>ass</em>}
/>
);
// => I have come here to chew bubblegum and kick ass... and I'm all out of bubblegum.
useInternational
, useLocale
and useT
are hooks that allow access to the locale context. useInternational
is the main hook, useLocale
and useT
are convenience shortcuts.
import { useInternational, useLocale, useT } from 'i18n-polyglot';
const MyComponent = ({ t, locale }) => {
const { t, locale } = useInternational();
// or
const locale = useLocale();
// or
const t = useT();
// ...
};
withLocale
is a HOC you can use to wrap your components to get access to the internationalization context. It's considered legacy and will be removed in the future versions. It is preferrable to use hooks or the T
component.
import { withLocale } from 'i18n-polyglot';
const MyComponent = ({ t, locale }) => (
// ...
);
export default withLocale(MyComponent);
FAQs
A React wrapper for node-polyglot
The npm package i18n-polyglot receives a total of 158 weekly downloads. As such, i18n-polyglot popularity was classified as not popular.
We found that i18n-polyglot demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 5 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.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.