0.0.2 • Published 4 years ago
lingua-switch v0.0.2
lingua-switch
Lingua Switch allows you to switch between multiple languages in your projects using your own translations.
Installation
Use the package manager npm to install lingua-switch.
npm install lingua-switch
Usage
Create json files with translations. Example:
{
"common": {
"res": "Response",
"success": "Successfull"
},
"auth-page": {
"pass": "Enter password",
"success": "Signed in successfully"
}
}
Initialize Lingua Switch in your app:
import { setLinguaSwitch } from "lingua-switch";
import en from "./en.json";
import ru from "./ru.json";
let options = {
currentLanguage: "en",
languages: {
en: en,
ru: ru,
},
};
setLinguaSwitch(options);
Use "translate" method to translate text anywhere in your app:
import { translate } from "lingua-switch";
<p>{translate("common.success")}</p>; // returns Successfull
Use "setLocale" method to change language:
import { translate } from "lingua-switch";
setLocale("ru");
<p>{translate("common.success")}</p>; // returns Успешно