0.0.2 • Published 4 years ago
react-gettext-context v0.0.2
react-gettext-context
A wrapper around the popular node-gettext module. It provides a very simple API to use the gettext function in an React application.
Sample:
//load the po file either statically or dynamically
const translations = require("./translations")
const { GettextProvider } = require("react-gettext-context")
// provide the translations to your application
const App = <GettextProvider
translations={ translations }
locales={ [ "en", "de" ] }
>
// ... components
</GettextProvider>
Within your application you can then access the translations via.
const { _ } = require("react-gettext-context")
const Button = () => <button>
{ _("my message") }
</button>
For react component attributes you can use a GettextConsumer.
const { GettextConsumer } = require("react-gettext-context")
const Input = () => <GettextConsumer msgid="my message">
{ text =>
<input placeholder={ text } />
}
</GetextConsumer>