1.2.0 • Published 6 years ago

react-dead-simple-translations v1.2.0

Weekly downloads
9
License
MIT
Repository
-
Last release
6 years ago

💀 react dead simple translations

Wrapping with <TProvider /> component

// import the Provider
import { TProvider } from "react-dead-simple-translations";

// load your messages however you want
const messages = {
  en: {
    name: "bob"
  }
};

const App = () => {
  // wrap your app in the TProvider component
  return <TProvider messages={messages}>app</TProvider>;
};

accessing messages with <T /> component

render prop

import { T } from "react-dead-simple-translations";

...

<T id="name">{m => `hello ${m}`}</T>; // hello bob

string

import { T } from "react-dead-simple-translations";

...

<T>name</T> // bob

accessing messages using props.getMessage using withT

```javascript
import { withT } from "react-dead-simple-translations";

const Hello = ({ getMessage }) => <span>{getMessage('name')}</span>;

const HelloEnhanced = withT(Hello)

<HelloEnhanced /> // bob