forwardemail / email-templates

Create, preview (browser/iOS Simulator), and send custom email templates for Node.js. Made for @forwardemail, @ladjs, @cabinjs, @spamscanner, and @breejs.
https://forwardemail.net/docs/send-emails-with-node-js-javascript
MIT License
3.64k stars 339 forks source link

Is there any date/number/currency formatting tools with i18n? #440

Closed AnToHu0 closed 2 years ago

AnToHu0 commented 2 years ago

Many of I18n realisations has formatting syntax like t('intlNumber', { val: product.price}) to format number like 8990 to 8 990. Also like currency and date formatting tools. So is there any possibility to use such formatters with this package?

titanism commented 2 years ago

For number formatting see https://www.npmjs.com/package/@lightspeed/i18n-number-format or https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat. For the former, you'd have to pass this as a function to locals variable.

For date formatting see https://day.js.org/docs/en/durations/locale. You'd have to provide a locals variable of dayjs that has all these plugins enabled and locales you support already require'd.

There's also https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleString which works in Node.js too.

Reference the README at https://github.com/forwardemail/email-templates to see what locals is and how to use it. You can define a global locals which will be inherited, or only do it for specific emails.