Code Monkey home page Code Monkey logo

Comments (5)

kaisermann avatar kaisermann commented on July 26, 2024

Currently there's no way of formatting numbers with a compact notation (look for compact here). It seems that this API is experimental, so intl-formatmessage doesn't offer support for it.

For now, I can expose an API to create custom formatters in the user-land. To do this, it'd probably be a breaking-change, since I'd need to modify the signature of the _ methods.

from svelte-i18n.

kaisermann avatar kaisermann commented on July 26, 2024

Something like:

  1. When initialising the i18n store, add some custom formats (number or date or time). The format props will be passed directly to the Intl.NumberFormat or Intl.DateTimeFormat.
import {
  dictionary,
   ...,
  addCustomFormats,
} from 'svelte-i18n'

addCustomFormats({
  number: {
    compact: {
      notation: 'compact',
      compactDisplay: 'long',
    },
  },
})
  1. On your template, call the _.number method specifying the format:
Number util: {$_.number(10000, { format: 'compact' })}

from svelte-i18n.

kaisermann avatar kaisermann commented on July 26, 2024

This change can bring some flexibility, but it includes having to rewrite all interpolated translations from:

$_('path.to.message', { name: 'John', lastname: 'Doe' })

to

$_('path.to.message', { values: { name: 'John', lastname: 'Doe' }}).

The first argument is still the message path on the dictionaries, but the second (interpolations) and third (locale) args become a single object which can receive any kind of props, like format. This way, you wouldn't need to pass null for interpolations in case of wanting to force a locale$_('message', null, 'pt-BR')

from svelte-i18n.

kaisermann avatar kaisermann commented on July 26, 2024

Played around a bit and you can test a version of what I said above in the https://github.com/kaisermann/svelte-i18n/tree/feat/options-object branch.

from svelte-i18n.

brunoamancio avatar brunoamancio commented on July 26, 2024

It's more flexible with the ability to include custom formats :) The breaking changes could also released in a new version, so people using the older signatures can explicitly migrate, if needed. PS.: I'm Brazilian as well, but live in the EU :)

from svelte-i18n.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.