John Smith
John Smith

Reputation: 138

is not a function occurs when i try to import node module when using require/ =new

This seems incredibly straight forward but for some reason i can't see what the issue is, im trying to import a node module which i've installed, like below

const Y18n = require('y18n')
const i18n = new Y18n()

However i get the following error:

i18n.__ is not a function

Why does this method of import not seem to work, it works for other node modules? Thanks!

Upvotes: 0

Views: 503

Answers (1)

Mr. Polywhirl
Mr. Polywhirl

Reputation: 48600

Looks like you did not use y18n correctly, have you checked the README?

const __ = require('y18n')().__;
console.log(__('my awesome string %s', 'foo')); // my awesome string foo

y18n.__(str, arg, arg, arg)

Print a localized string, %s will be replaced with args.

This function can also be used as a tag for a template literal. You can use it like this: __`hello ${'world'}` . This will be equivalent to __('hello %s', 'world').

Upvotes: 2

Related Questions