Plugin for translation
npm i @andrewcaires/translate
import { Translate } from "@andrewcaires/translate";
Translate.options({
locale: "en",
locales: {
"en": {
"Hello world": "Hello world",
},
"pt": {
"Hello world": "Olá Mundo",
},
},
});
console.log(Translate.to("Hello world"));
-
translate
Translate a message
const text = Translate.to("Hello world");
const text = Translate.to("Hello {name}", { name: "John" });
const text = Translate.to("Hello {name}", { name: "John" }, "en");
-
getLocale
Get language for translation
const locale = Translate.getLocale();
-
setLocale
Set language for translation
Translate.setLocale("en");