
Security News
New React Server Components Vulnerabilities: DoS and Source Code Exposure
New DoS and source code exposure bugs in React Server Components and Next.js: what’s affected and how to update safely.
react-i18n-kit
Advanced tools
I18n for your React Components
I needed a simple way to translate my react applications without to much overhead.
$ npm i react-i18n-kit -S
or
$ yarn add react-i18n-kit
For more detailed information you can take a look at the documentation.
This is the enhancer for your Components. If you wrap your Components in this function you get access to a i18n and a translate property.
Returns a component which renders the wrapped Component.
const i18n = withI18n(Component, data, options);
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
| Component | Component | true | The component that gets rendered | |
| data | object | true | The translations for your Component | |
| options | object | false | The options for your translations |
An example for the Component parameter.
This component gets access to 2 exposed properties.
| Property | Type | Description |
|---|---|---|
| i18n | object | The committed data object, but only for the corresponding language |
| translate | func | The function for the dynamic translation (e.g. on a button click) |
const Text = (props) => (
<div>
<button onClick={() => props.translate('en')}>
English
<button/>
<button onClick={() => props.translate('de')}>
Deutsch
<button/>
{props.i18n.text}
</div>
);
An example for the data parameter.
const data = {
de: {
text: "Hallo Welt!",
},
en: {
text: "Hello World!",
},
};
If there is no translation for a language it will take the
fallbackwhich is default toen
An example for the options parameter.
const options = {
lang: "de",
fallback: "de",
};
For more detailed information you can take a look at the documentation
Render a text based on the users browser language. If your browsers language is set to de it will render Hallo Welt! and if the browsers language is set to en it will render Hello World!.
import React from "react";
import { withI18n } from "react-i18n-kit";
const data = {
de: {
text: "Hallo Welt!",
},
en: {
text: "Hello World!",
},
};
/*
if language is:
- en:
props.i18n.text: "Hello World!"
- de:
props.i18n.text: "Hallo Welt!"
*/
const Text = props => <div>{props.i18n.text}</div>;
const TextI18n = withI18n(Text, data);
export { TextI18n as Text };
As you see you get access to a i18n property. To make that enhancer work properly we have to pass an object with with keys set to a ISO 639-1 code. Then the enhancer simply passes only the object with the corresponding language to the i18n property.
For example your browser language is set to en-US, props.i18n will be:
{
"text": "Hello World!"
}
You can pass everything you want into these objects, but every language object has to contain the same keys (in this example text), which you will use in your enhanced component.
If you do not want to deside the language based on the browser language and you want to have a default value you can pass a options object.
If the user is visiting the page with a browser which has its language set to zh (chinese) it will automatically fallback to en since there is no translation for zh right now.
import React from "react";
import { withI18n } from "react-i18n-kit";
const data = {
de: {
text: "Hallo Welt!",
},
en: {
text: "Hello World!",
},
};
const Text = props => <div>{props.i18n.text}</div>;
const TextI18n = withI18n(Text, data, { fallback: "en" });
export { TextI18n as Text };
MIT © Lukas Aichbauer
FAQs
I18n for your React Components
The npm package react-i18n-kit receives a total of 8 weekly downloads. As such, react-i18n-kit popularity was classified as not popular.
We found that react-i18n-kit demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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
New DoS and source code exposure bugs in React Server Components and Next.js: what’s affected and how to update safely.

Security News
Socket CEO Feross Aboukhadijeh joins Software Engineering Daily to discuss modern software supply chain attacks and rising AI-driven security risks.

Security News
GitHub has revoked npm classic tokens for publishing; maintainers must migrate, but OpenJS warns OIDC trusted publishing still has risky gaps for critical projects.