Langlate
React Component which makes multilingualism easier.
Install
- Download package via
npm i langlate
- Import using
var Langlate = require('langlate')
or for ES6import Langlate from 'langlate'
Usage
You can use langlate as a React Component or get the translation returned by the raw
method as a string.
Component
<Langlate text={object} language={string} \>
Function
Langlate.raw(object text, string language);
Arguments
- 'text' [object] contains language keys and corresponding translations. (e.g.
{ en_US: "Hello World" }
) - 'language' [string] is the language in which the translation will be returned. (e.g.
"en_US"
)
Documentation & Demo
Can be found here - documentation and demo
Example
import React from "react";import render from "react-dom";import Langlate from "langlate"; Component { /** Object containing translations. */ const helloWorld = en_US: "Hello World" pl_PL: "Witaj Świecie" de_DE: "Hallo Welt" es_ES: "Hola Mundo" ; return <h2> <Langlate = = /> </h2> ; } ;
Give it a try on codesandbox.io
Build instructions
After cloning the repo, install all dependencies using npm install
.
Run the development mode:
npm run dev
Run just the docs:
npm run docs
Run just the library:
npm run lib
Deploy the production-ready docs:
npm run docs:prod
Test the library:
npm test