
Security News
Axios Supply Chain Attack Reaches OpenAI macOS Signing Pipeline, Forces Certificate Rotation
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.
react-translate
Advanced tools
Internationalization for react
$ npm install --save react-translate
# or
$ yarn add react-trasnlate
import { TranslatorProvider, useTranslate } from "react-translate"
let translations = {
locale: "en",
Home: {
"HELLO": "Helloworld!"
}
};
function Home() {
let t = useTranslate("Home");
return <h1> {t("HELLO")} </h1>
}
function App() {
return (
<TranslatorProvider translations={translations}>
<Home />
</TranslatorProvider>
)
}
import { TranslatorProvider, translate } from "react-translate"
let translations = {
locale: "en",
Home: {
"HELLO": "Helloworld!"
}
};
let Home = function({t}) {
return <h1> {t("HELLO")} </h1>
}
Home = translate("Home")(Home);
function App() {
return (
<TranslatorProvider translations={translations}>
<Home />
</TranslatorProvider>
)
}
<TranslatorProvider translations={object} />Provides the translation data for descendant components.
import { render } from "react-dom";
import { TranslatorProvider } from "react-translate";
// …
render(
<TranslatorProvider translations={translations}>
<App />
</TranslatorProvider>,
mountNode
);
Returns a t function that returns translations under namespace.
Wraps a component and passes a t function as a prop.
namespace (String)const Header = ({ t }) => <div> {t("TITLE")} </div>;
export default translate("Header")(Header);
The t function is the one that returns your translations given the key, and optionally some parameters.
// for a simple key
t("KEY"); // "value"
// for a key with a parameter
t("KEY", { foo: "bar" }); // replaces "{{foo}}" in the translation with "bar"
// for a key with a numeral parameter, which makes `t` choose between singular
// and plural
t("KEY", { n: 2 });
translations objectTranslations should be grouped by component:
const translations = {
// the `locale` parameter is mandatory, it enables react-translate to use
// the right rules for singular and plural
locale: "fr",
ComponentName: {
SIMPLE_KEY: "Helloworld",
KEY_WITH_PARAMS: "Hello {{name}}",
KEY_WITH_PLURAL: ["You have {{n}} message", "You have {{n}} messages"]
}
};
ReactTranslate does not give you a specific way to load translations, its goal is only to provide a way to pass translations down to your app components'.
You can use a simple XHR call, put translations in a <script> in
your HTML page, or any other way you find adequate.
FAQs
react utilities for simple i18n
The npm package react-translate receives a total of 1,610 weekly downloads. As such, react-translate popularity was classified as popular.
We found that react-translate 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
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.

Security News
Open source is under attack because of how much value it creates. It has been the foundation of every major software innovation for the last three decades. This is not the time to walk away from it.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.