Closed max-petrenko closed 3 months ago
Hey @max-petrenko and thanks for the kind words!
I think this is what you're looking for: Custom prefixes.
Let me know if that helps!
So, do I understand it correctly that the way to go is to change all references to ua
for uk
, and alias the uk
route prefix to be displayed as ua
(or whatever else I come up with)? If so, it's a way do go indeed in my case (took me about 10 minutes to rewire the whole app - a really slick DX indeed), but you may want to consider adding formatting options override anyway - just in case it doesn't work for somebody else.
Description
First of all, thanks for creating this tool, it has helped me a lot across several projects.
While I'm not entirely sure whether the issue in question is a bug or a missing feature, it prevents me from achieving a desired result, so I'll post it here.
I am creating a website in Ukrainian, it uses
ua
as a locale name. While everything works fine, date manipulations either via the embedded ICU syntax or by usingformatter.dateTime
are giving me strings in English, which seems to be the fallback in JS. Upon investigation, I've realised theIntl.DateTimeFormat
(which, I presume, to be used by both embeds and formatter) is using BCP47 country/locale codes, which in case of Ukraine isuk
, notua
. Therefore, Intl can't recognise it and falls back to the English version.As there is no way to directly pass locale to either of these date formatting methods, the only way to resolve the issue is to wrap the component that relies on date formatting into a
NextIntlClientProvider
with thelocale
prop set touk
. Then, both the formatter and the embedded ICU dates are rendering as expected. Therefore, to make the whole setup work without these manipulations I need to either change 'ua' for 'uk' across all the app, or have a way to override thelocale
setting for date formatting utils on app-wide or per-use level.A possible quick fix might be the ability to override params used at
createFormatter
invocation by allowing to supply them to theuseFormatter
hook here: https://github.com/amannn/next-intl/blob/44a87a4ff07e779df8ac929c0edcf22fb398f576/packages/use-intl/src/react/useFormatter.tsx#L5Another option would be to allow for locale override in the
formats.dateTime
section of thegetRequestConfig
function call.Hope I've laid out my problem and the possible ways to fix it clearly.
Verifications
Mandatory reproduction URL
https://github.com/max-petrenko/next-intl-date-formatting-bug
Reproduction description
Steps to reproduce:
Expected behaviour
The dates are rendered in Ukrainian (either by default or by using a simple way to configure the locale parameter for date formatting utils)