Skip to content

Commit

Permalink
feat: 🎸 add custom formats support
Browse files Browse the repository at this point in the history
BREAKING CHANGE: This PR modifies the formatter method arguments.
  • Loading branch information
kaisermann committed Nov 22, 2019
1 parent f056e70 commit d483244
Show file tree
Hide file tree
Showing 6 changed files with 1,324 additions and 1,189 deletions.
11 changes: 6 additions & 5 deletions example/src/App.svelte
@@ -1,5 +1,5 @@
<script>
import { locale, _ } from 'svelte-i18n'
import { locale, _ } from '../../src/index.js'
let name = ''
let pluralN = 2
Expand All @@ -20,18 +20,19 @@
bind:value={name} />
<br />

<h1>{$_.title('greeting.message', { name })}</h1>
<h1>{$_.title('greeting.message', { values: { name } })}</h1>

<br />
<input type="range" min="0" max="5" step="1" bind:value={pluralN} />
<h2>Plural: {$_('photos', { n: pluralN })}</h2>
<h2>Plural: {$_('photos', { values: { n: pluralN } })}</h2>

<br />
<input type="range" min="100" max="100000000" step="10000" bind:value={catsN} />
<h2>Number: {$_('cats', { n: catsN })}</h2>
<h2>Number: {$_('cats', { values: { n: catsN } })}</h2>

<br />
<h2>Number util: {$_.number(catsN)}</h2>
<h2>Number util: {$_.number(10000000, { format: 'compactShort' })}</h2>

<br />
<h2>Date util: {$_.date(date, 'short')}</h2>
Expand All @@ -41,5 +42,5 @@

<br />
<button on:click={() => locale.set(oppositeLocale)}>
{$_('switch.lang', null, oppositeLocale)}
{$_('switch.lang', { locale: oppositeLocale })}
</button>
18 changes: 16 additions & 2 deletions example/src/i18n.js
@@ -1,4 +1,18 @@
import { locale, dictionary, getClientLocale } from 'svelte-i18n'
import {
locale,
dictionary,
getClientLocale,
addCustomFormats,
} from '../../src/index.js'

addCustomFormats({
number: {
compact: {
notation: 'compact',
compactDisplay: 'long',
},
},
})

// defining a locale dictionary
dictionary.set({
Expand Down Expand Up @@ -34,4 +48,4 @@ locale.set(

locale.subscribe(l => {
console.log('locale change', l)
})
})

0 comments on commit d483244

Please sign in to comment.