Comments (5)
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.
Something like:
- When initialising the i18n store, add some custom formats (
number
ordate
ortime
). The format props will be passed directly to theIntl.NumberFormat
orIntl.DateTimeFormat
.
import {
dictionary,
...,
addCustomFormats,
} from 'svelte-i18n'
addCustomFormats({
number: {
compact: {
notation: 'compact',
compactDisplay: 'long',
},
},
})
- On your template, call the
_.number
method specifying theformat
:
Number util: {$_.number(10000, { format: 'compact' })}
from svelte-i18n.
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.
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.
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)
- Sveltekit: Update translation outside of component
- Variable inside html isn't replaced HOT 1
- Inform about unused language keys HOT 1
- When I hover over a <a> the site language changes to the default language. HOT 1
- `intl-getcanocicallocales` is probably not a good idea HOT 2
- CJS / ESM conflict HOT 22
- Change log version comparison links are off
- Production build using svelte-i18n ^3.7.4 throws "Named export 'IntlMessageFormat' not found." HOT 6
- Problems with LIB check in cli extractor HOT 1
- Sapper reference in Getting Started guide
- Allow to restrict some parts of the i18n file to unauthorized users in SvelteKit. HOT 3
- Is it possible when registering several json files to overwrite the previous key contents with latest file?
- Docs on how to use variables in translation strings HOT 1
- How to disable AM/PM in $time formatter
- Leading zeros for day/month when formatting date values
- Add a register store?
- Build error when deploying in vercel
- Provide a Readable<string> instead of pure string
- Svelte 5 support
- Disable automatic "lang" attribute setting
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from svelte-i18n.