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

Why am I getting (US$) and not ($) #86

Open
rochapablo opened this issue Apr 20, 2017 · 6 comments
Open

Why am I getting (US$) and not ($) #86

rochapablo opened this issue Apr 20, 2017 · 6 comments

Comments

@rochapablo
Copy link

rochapablo commented Apr 20, 2017

I'm using

"email-templates": "^2.5.4",
"handlebars": "^4.0.6",
"handlebars-intl": "^1.1.2",
"handlebars-layouts": "^3.1.4"

This is how I'm formatting

{{formatNumber price style="currency" currency="USD" locales="en-US"}}

And here's my js file

const handlebars = require('handlebars');
const handlebarsIntl = require('handlebars-intl');

handlebarsIntl.registerWith(handlebars);
handlebars.registerHelper(layouts(handlebars));
handlebars.registerPartial('layout', fs.readFileSync(`public/email-template/layout.hbs`, 'utf8'));

var intlData = {
  locales: 'en-US'
  // I also tried to follow this: https://formatjs.io/handlebars/ (Using Named Number Formats)
};

var newsletter = new EmailTemplate(path, {
  data: { intl: intlData }
});
handlebars.registerPartial('data', { intl: intlData });

newsletter.render({ params: { ... }, data: { intl: intlData } }, function (err, result) {
  if(err) { return reject(err); }
  return resolve(result.html);
});

Everything that I tried, or nothing happens or I got this error

ReferenceError: Could not find Intl object: formats.number.USD at intlGet (E:\www\unclehub\v0.2.2\api\node_modules\handlebars-intl\lib\helpers.js:96:23)
@gregholland
Copy link

@rochapablo did you have any luck solving this? I'm having the same issue.

@rochapablo
Copy link
Author

@gregholland, nop. I kind give up for now. I'm working in other areas and I'll let this for later.

@paulfalgout
Copy link

Honestly I don't think this issue has to do with this lib. Under the hood it uses the browsers intl API which is what is using US$ instead of $. So likely in testing this is the browser using a different locale than en-US. You can see in the polyfill what I mean: https://github.com/andyearnshaw/Intl.js/search?p=19&q=%22US%24%22&type=&utf8=%E2%9C%93

@paulfalgout
Copy link

Oh and the formats part of the intl file is mostly for shorthand.. so instead of typing {{formatNumber fooNum style="currency" currency="USD"}} with a format you can just do {{formatNumber fooNum "bar"}} where

var intlData = {
    "locales": "en-US",
    "formats": {
        "number": {
            "bar": {
                "style": "currency",
                "currency": "USD"
            }
        }
    }
};

I honestly can't find good reason to use them.. seems hard to maintain.

@azhiv
Copy link

azhiv commented Dec 28, 2017

I was able to solve the problem using singular 'locale' form:
{{formatNumber price style="currency" currency="USD" locale="en-US"}}

@Pooja-N-Swamy
Copy link

Pooja-N-Swamy commented Jan 25, 2021

Need to use currencyDisplay: 'narrowSymbol' to display $ instead of US$ . Please refer https://stackoverflow.com/questions/52410407/intl-numberformat-currency-us-currency-symbol

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

5 participants