Security News
38% of CISOs Fear They’re Not Moving Fast Enough on AI
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
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
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
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.
Security News
Company News
Socket is joining TC54 to help develop standards for software supply chain security, contributing to the evolution of SBOMs, CycloneDX, and Package URL specifications.