Reputation: 9597
I'm feeding the value of navigator.language
into await import('.../date-fns/locales/${languageCode}')
which fails for de-DE
as date-fns
does not define de-DE
, but it does de
. I find myself manually stripping the -DE
from de-DE
and retrying, but this leads to a 404 error for the initial attempt.
It doesn't feel very clean to have to make a 404 attempt before falling back to the 2-letter language locale. I'd hope for a utility function that knows which locales are available in the library and automatically falls back, without ever causing the initial 404.
Is this the right way to dynamically import localization utilities from date-nfs
or is there a better way?
Background: Using BlueprintJS and following instructions for localization.
Upvotes: 0
Views: 11