Closed juanpmarin closed 8 months ago
Maybe you are looking for relative times? https://github.com/robisim74/qwik-speak/blob/main/docs/translate.md#userelativetime
E.g.:
const rt = useRelativeTime();
<p>{rt(-0, 'day', {numeric: 'auto'})}</p> {/* today */}
<p>{rt(-1, 'day', {numeric: 'auto'})}</p> {/* yesterday */}
<p>{rt(-2, 'day', {numeric: 'auto'})}</p> {/* 2 days ago */}
The Plural function also uses Intl, so if you want to use the plural you have to handle the zero value yourself:
{!count.value && t('zero')}
{count.value > 0 && p(count.value, 'devs')}
That's because only some locales support zero cardinal. More info here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/PluralRules
@robisim74 I think that solves it, thanks!
Hi!
I have one use case that would love to solve with qwik-speak.
For a list item I'm showing the days since it was created, I want to display it like this:
0 days: "Today"` 1 day: "A day ago"
Is it possible to achieve this with qwik-speak?