-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(i18n): format currency using Sanity site locale and currency fields
- Loading branch information
Showing
9 changed files
with
160 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export function formatAsCurrency( | ||
number: number, | ||
locale: string, | ||
currency: string, | ||
) { | ||
return new Intl.NumberFormat(locale, { style: "currency", currency }).format( | ||
number, | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// ISO 4217 currency codes (https://en.wikipedia.org/wiki/ISO_4217#List_of_ISO_4217_currency_codes) | ||
export const relevantCurrencies = [ | ||
"NOK", | ||
"SEK", | ||
"EUR", | ||
"GBP", | ||
"USD", | ||
"DKK", | ||
"ISK", | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
interface Locale { | ||
title: string; | ||
code: string; | ||
} | ||
|
||
export const relevantLocales: Locale[] = [ | ||
{ | ||
title: "Norway", | ||
code: "nb-NO", | ||
}, | ||
{ | ||
title: "Norway", | ||
code: "nn-NO", | ||
}, | ||
{ | ||
title: "Sweden", | ||
code: "sv-SE", | ||
}, | ||
{ | ||
title: "United Kingdom", | ||
code: "en-GB", | ||
}, | ||
{ | ||
title: "United States", | ||
code: "en-US", | ||
}, | ||
{ | ||
title: "Denmark", | ||
code: "da-DK", | ||
}, | ||
{ | ||
title: "Finland", | ||
code: "fi-FI", | ||
}, | ||
{ | ||
title: "Iceland", | ||
code: "is-IS", | ||
}, | ||
]; |