@oneforx/react-translator
TypeScript icon, indicating that this package has built-in type declarations

1.0.3 • Public • Published

@oneforx/react-translator

This library is intent to be used as a translator of predefined json file that can be created with react-translator-gui website

locales.json

{"translate_key":{"fr":"Je suis une traduction","au":"I'm a translation"}}

Example of initialisation

import locales from './locales.json'

  const ExampleComponent = () => {
    const translateKey = useTranslator("translate_key");

    return (
      <div>{translateKey}<div>
    )
  }
  const ExampleComponent2 = () => {
    const translated = useTranslator();

    return (
      <div>{translated["translate_key"]}<div>
    )
  }
  const App = () => {
    return (
      <ReactTranslatorContextProvider locales={locales}>
        {/**Your components*/}
      </ReactTranslatorContextProvider>
    );
  }

Optimisation

Support for translation in webworker to minimize work done by main web worker, cool for large file. Not fun for old browser that don't support webworker :p

Readme

Keywords

none

Package Sidebar

Install

npm i @oneforx/react-translator

Weekly Downloads

3

Version

1.0.3

License

MIT

Unpacked Size

70.7 kB

Total Files

8

Last publish

Collaborators

  • bawdeveloppement