-
-
Notifications
You must be signed in to change notification settings - Fork 294
Support Intl.RelativeTimeFormat for relativeTime
formatting
#1056
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hey, thanks for the report! I agree, we could definitely support As for See also: next-intl/packages/use-intl/src/core/createFormatter.tsx Lines 247 to 257 in 3eefe6f
Do you need I've added #1057 to look into this. |
At the moment, I only have a need for the I think numberingSystem and style is sufficient for now! |
Sounds good, thanks for the feedback! |
Circling back to this @amannn I have come across needing the |
Interesting. Can you share what your exact use case is? From my personal observation, "yesterday" is a nice thing to read, but it's easy to run into a wrong output due to rounding (see #1056 (comment)). "Yesterday" might not actually be the day before today, but could be the day before yesterday. |
The use case is exactly as described, requiring the use of localizations for "yesterday" and "today". I don't think we should be too worried about the rounding because IMO the idea is that doing the correct math beforehand is a prerequisite that's on the onus of the developer (otherwise it wouldn't make much sense for the official For what it's worth, what I'm currently doing is I'm using Luxon to do proper date-time calculations of the math in "days" (with the local machine timezones set) via |
Let me know if you would like me to open a new issue to track this discussion! |
The current output would be "1 day ago" instead of "yesterday". I'd say that "yesterday" reads a bit nicer, but the rounding problem make this a bit error prone. Is there a particular issue with using "1 day ago" in your app?
So with However, next-intl/packages/use-intl/src/core/createFormatter.tsx Lines 69 to 71 in 9a70cef
The docs mention this capability:
So if That's at least my current understanding. I might have to give this more thought, but it seems like a potentially problematic feature to support. What do you think? |
Yes, the designers specifically want more friendly localized dates for "today" and "yesterday", instead of "1 day ago". Currently I'm fetching the locale via next-intl's |
Also as a side note, in other languages, the equivalent localizations of "yesterday" as opposed to "1 day ago" and "today" instead of "in 0 days" sounds much less awkward. In Chinese for example, "1 day ago" is "1天前", but this is not a phrase that anyone would ever use colloquially, the better way would be "昨天" which transliterates to "yesterday". And for "in 0 days", the phrase "0天后" wouldn't even make sense to use anywhere and would actually seem like an error whereas "今天" is the correct translation for "today". The point of this add-on comment here is to express why |
Hmm, I have another idea here. What if Here's a PR with a proposal: #1872. What do you think? I might have to give it another thought and see if this feels right when writing docs, but it could be an option. |
@kvnxiao Do you by chance have an idea if this code snippet could be simplified? https://github.com/amannn/next-intl/pull/1872/files#r2071663776 Also I'm still wondering if there are edge cases that I'm overlooking … Or maybe cases where |
I like the idea so far, took a look over the PR itself and had left a comment: https://github.com/amannn/next-intl/pull/1872/files#r2072115257 |
Is your feature request related to a problem? Please describe.
Currently, the formatter for
Formatting date and time ranges
does not support additional configuration other than specifying the exact unit to display the output in.The relative time formatting should support all the options from
Intl.RelativeTimeFormat
and not justRelativeTimeFormatUnit
Describe the solution you'd like
Instead of:
The
RelativeTimeFormatOptions
type should also accept the options from theIntl.RelativeTimeFormat
constructor:Describe alternatives you've considered
The only alternative would be to use the native
Intl
API directly, but this should be integrated into the formatter innext-intl
IMOThe text was updated successfully, but these errors were encountered: