From 5147f346ceae7e759445d531e10d608fca0d1f6a Mon Sep 17 00:00:00 2001 From: Tom Lienard Date: Tue, 15 Feb 2022 15:59:35 +0100 Subject: [PATCH 1/2] docs(use-i18n): add `formatList` to README.md --- packages/use-i18n/README.md | 40 +++++++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/packages/use-i18n/README.md b/packages/use-i18n/README.md index 52f8b756c..9c920b7c7 100644 --- a/packages/use-i18n/README.md +++ b/packages/use-i18n/README.md @@ -186,8 +186,8 @@ const App = () => { const { formatDate } = useI18n() const units = [ - formatDate(new Date(2020, 1, 13, 16, 28)) // "Feb 13, 2020" - formatDate(1581607680000, 'long') // "February 13, 2020" + formatDate(new Date(2020, 1, 13, 16, 28)), // "Feb 13, 2020" + formatDate(1581607680000, 'long'), // "February 13, 2020" formatDate('2020-02-13T15:28:00.000Z', { day: "numeric", era: "short", @@ -209,6 +209,38 @@ const App = () => { } ``` +### formatList + +This hook exposes a `formatList` function which can be used to format lists of strings. + +The first parameter is an array of strings to format. + +It accepts an `options` as second parameter which is an [Intl.ListFormat `options` object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/ListFormat). + +```js +import { useI18n } from '@scaleway/use-i18n' + +const App = () => { + const { formatList } = useI18n() + + const cities = formatList(['Paris', 'New York', 'London']) + // Paris, New Yo + + const cities = [ + formatList(['Paris', 'New York', 'London']), // Paris, New York and London + formatList(['Paris', 'New York', 'London'], { + type: 'disjunction' + }) // Paris, New York or London + ] + + return ( +
+ {cities} +
+ ) +} +``` + ### formatUnit This hook also exposes a `formatUnit` function which can be used to format bits/bytes until [ECMA-402 Unit Preferences](https://github.com/tc39/proposal-smart-unit-preferences) is standardised @@ -229,8 +261,8 @@ const App = () => { const { formatUnit } = useI18n() const units = [ - formatUnit(12, { unit: 'kilobyte' }) // "12 KB" or "12 Ko" in fr an ro - formatUnit(10 ** 8, { unit: 'bytes-humanized' }) // "100 MB" or "100 Mo" in fr an ro + formatUnit(12, { unit: 'kilobyte' }), // "12 KB" or "12 Ko" in fr an ro + formatUnit(10 ** 8, { unit: 'bytes-humanized' }), // "100 MB" or "100 Mo" in fr an ro formatUnit(10 ** 8, { unit: 'bits-per-second-humanized' }) // "100Mbs" ] From 37a1acfbdecfb5f8fb02eee27817bf0f2f31fb6a Mon Sep 17 00:00:00 2001 From: Tom Lienard Date: Tue, 15 Feb 2022 16:04:49 +0100 Subject: [PATCH 2/2] fix: old code example --- packages/use-i18n/README.md | 3 --- 1 file changed, 3 deletions(-) diff --git a/packages/use-i18n/README.md b/packages/use-i18n/README.md index 9c920b7c7..9dfdc6865 100644 --- a/packages/use-i18n/README.md +++ b/packages/use-i18n/README.md @@ -223,9 +223,6 @@ import { useI18n } from '@scaleway/use-i18n' const App = () => { const { formatList } = useI18n() - const cities = formatList(['Paris', 'New York', 'London']) - // Paris, New Yo - const cities = [ formatList(['Paris', 'New York', 'London']), // Paris, New York and London formatList(['Paris', 'New York', 'London'], {