How to use Polyglot.js in my Webpack Project?

Viewed 329

Trying to use Polyglot for the first time in my Webpack project but keep getting the error that polyglot is not defined. Can I import it from node somewhere? Or do I need to import them local?

var polyglot = new Polyglot();

polyglot.extend({
  "hello": "Hello"
});

polyglot.t("hello");
1 Answers

You have to import or require the module before using it.

import Polyglot from 'polyglot';
// const Polyglot = require('polyglot');

const polyglot = new Polyglot();

polyglot.extend({ "hello": "Hello" });

polyglot.t("hello");

Related