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

Add Feature: Make possible to explicitly specify currency when localising numbers. #301

Closed
bponomarenko opened this issue Mar 1, 2018 · 3 comments

Comments

@bponomarenko
Copy link
Contributor

bponomarenko commented Mar 1, 2018

Hi. Thanks for this plugin, it works really well for us. However there is one use case, which can't be implemented with vue-i18n at the moment.

Use case

We need to display a list of formatted amounts in different currencies.
Data structure may look like this:

const transactions = [
  { amount: 10123.45, currency: 'EUR' },
  { amount: 23.00, currency: 'GBP' },
  { amount: 45.40, currency: 'USD' },
];

Feature request

Make it possible to explicitly specify currency when localising numbers.

Current set of arguments for $n() function looks like this:

  • {number} value: required
  • {Path | Object} key: optional
  • {Locale | Object} locale: optional

This makes it possible to extend the second key: Object argument by adding optional currency option, which will override default value from the numberFormats configuration.

Example of possible API

Number formats:

const numberFormats = {
  'en-US': {
    currency: {
      style: 'currency',
      currency: 'USD',
      currencyDisplay: 'code'
    }
  }
}

Template:

<ul v-for="transaction in transactions">
  <li>{{ $n(transaction.amount, { key: 'currency', currency: transaction.currency }) }}</p>
  <!-- Or use it even as a fallback options:
  <li>{{ $n(transaction.amount, { style: 'currency', 'currency': transaction.currency, currencyDisplay:
 'code' }) }}</li>
  -->
</ul>

Expected result:

<ul>
  <li>EUR 10,123.45</li>
  <li>GBP 23.00</li>
  <li>USD 45.40</li>
</ul>
@bponomarenko bponomarenko changed the title Make possible to explicitly specify currency when localising numbers. Add Feature: Make possible to explicitly specify currency when localising numbers. Mar 3, 2018
@bponomarenko
Copy link
Contributor Author

@kazupon I can create PR if you ok with proposed API.

@kazupon
Copy link
Owner

kazupon commented Mar 5, 2018

@bponomarenko I look forward to your PR. :)

@kazupon
Copy link
Owner

kazupon commented Mar 9, 2018

closed (merge with #305)

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

3 participants