4.0.2 • Published 2 years ago

@mojang/t-component v4.0.2

Weekly downloads
36
License
MIT
Repository
github
Last release
2 years ago

t-component

This package contains <T/> component that allows you to translate strings in React using Jed.

Contributing

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

Install

To install this packages run:

$ npm i @mojang/t-component

or

$ yarn add @mojang/t-component

Usage

TranslationProvider

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(
    <TranslationProvider translation={messages}>
      <App />
    </TranslationProvider>,
    document.getElementById("React")
  );
});

T and useTranslation

import * as React from "react";

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

export const App = () => {
  const { t } = useTranslation();
  return (
    <div>
      <p><T>This text will be translated.</T></p>
      <p>
        <T
          placeholders={[
            "https://link",
          ]}
          isHTML
        >
          {`This text <a href='%1$s'>includes a link</a> to that will also be translated`}
        </T>
      </p>
      <p>
        {t("Texts can also be translated with the t function")}
      </p>
    <div/>
  )
}

Testing

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

$ npm test

or

$ yarn test

License

Licensed under MIT license.

4.0.2

2 years ago

3.0.2

3 years ago

4.0.1

3 years ago

4.0.0

4 years ago

3.0.1

4 years ago

3.0.0

4 years ago

2.5.0

4 years ago

2.4.2

4 years ago

2.4.1

4 years ago

2.4.0

4 years ago

2.3.3

4 years ago

2.3.2

4 years ago

2.3.0

4 years ago

2.3.1

4 years ago

2.2.3

4 years ago

2.2.1

4 years ago

2.2.0

4 years ago

2.2.2

4 years ago

2.1.6

4 years ago

2.1.5

4 years ago

2.1.4

4 years ago

2.1.3

4 years ago

2.1.2

4 years ago

2.1.1

5 years ago

2.1.0

5 years ago

2.0.1

5 years ago

2.0.0

5 years ago