Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/mojang/t-component

React translation component
https://github.com/mojang/t-component

Last synced: about 1 month ago
JSON representation

React translation component

Awesome Lists containing this project

README

        

# t-component

This package contains `` component that allows you to translate strings in React using [Jed](https://github.com/messageformat/Jed).

## Contributing

We are not accepting external contributions at this point in time.

## Install

To install this packages run:

```console
$ npm i @mojang/t-component
```

or

```console
$ yarn add @mojang/t-component
```

## Usage

### TranslationProvider

```tsx
import * as React from "react";
import * as ReactDOM from "react-dom";

import { TranslationProvider } from "@mojang/t-component";
import { App } from "./App";

const fetchMessages = async (path: string) => {
return (await fetch(path)).json();
};

fetchMessages("your/translation/path").then(messages => {
ReactDOM.render(


,
document.getElementById("React")
);
});
```

### T and useTranslation

```tsx
import * as React from "react";

import { T } from "@mojang/t-component";
import { App } from "./App";

export const App = () => {
const { t } = useTranslation();
return (


This text will be translated.




{`This text includes a link to that will also be translated`}



{t("Texts can also be translated with the t function")}



)
}

```

## Testing

To run tests, simply run the following command from the root:

```console
$ npm test
```

or

```console
$ yarn test
```

## License

[Licensed under MIT license](/LICENSE).