Security News
PyPI’s New Archival Feature Closes a Major Security Gap
PyPI now allows maintainers to archive projects, improving security and helping users make informed decisions about their dependencies.
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"
options={{
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
PyPI now allows maintainers to archive projects, improving security and helping users make informed decisions about their dependencies.
Research
Security News
Malicious npm package postcss-optimizer delivers BeaverTail malware, targeting developer systems; similarities to past campaigns suggest a North Korean connection.
Security News
CISA's KEV data is now on GitHub, offering easier access, API integration, commit history tracking, and automated updates for security teams and researchers.