Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to add custom formatters for MessageFormat #374

Open
nsamarak opened this issue Jun 16, 2018 · 0 comments
Open

Unable to add custom formatters for MessageFormat #374

nsamarak opened this issue Jun 16, 2018 · 0 comments

Comments

@nsamarak
Copy link

When using the i18n-node with MessageFormat, you're unable to add custom formatters to MessageFormat by using the static MessageFormat object. The example below illustrates adding a custom formatter to the static MessageFormat object.

MessageFormat.formatters.moment = function () {
    return function (value, locale, arg) {
        return moment(value).format(arg);
    };
};

The issue is caused by i18n-node packaging its own version of MessageFormat, which results in i18n-node having a different static MessageFormat object than all the other NPM modules. This because all the other NPM modules that depend on MessageFormat are looking at the top-level MessageFormat installation.

The MessageFormat lib that i18n-node requires:
APP_ROOT/node_modules/i18n/node_modules/messageformat

The MessageFormat lib that all the other modules require:
APP_ROOT/node_modules/messageformat

I tested deleting APP_ROOT/node_modules/i18n/node_modules/messageformat
and that works great -- now you can add custom formatters to the static MessageFormat object.

Should i18n-node stop packaging its own version of MessageFormat?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant