react-gettext-context

0.0.2 • Public • Published

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>

Readme

Keywords

Package Sidebar

Install

npm i react-gettext-context

Weekly Downloads

0

Version

0.0.2

License

MIT

Unpacked Size

363 kB

Total Files

7

Last publish

Collaborators

  • arwed