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 https://airbnb.io/polyglot.js/.
You need to use the <International />
wrapper around your app to create a https://airbnb.io/polyglot.js/ 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 contents:
type
: string, name of the locale, for possible values check (https://github.com/airbnb/polyglot.js/blob/master/index.js#L96)[here].dictionary
: object, same as phrases
object one would pass to https://github.com/airbnb/polyglot.js#translation.T
is a component that allows for JSX within your substitutions options.
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 hooks and useLocale
/useT
are convenience shortcuts.
import { useInternational, useLocale, useT } from 'i18n-polyglot';
const MyComponent = ({ t, locale }) => {
const { t, locale } = useInternational();
const locale = useLocale();
const t = useT();
//...
};
withLocale
is a HOC you can use to wrap your components to get access to the t
translations function. It's considered legacy, 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
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.