Format dates, times with window.navigator.language instead of UI i18n locale #354
No reviewers
Labels
No labels
a11y
Bug
Bug fix
Critical Priority
Documentation
Feature
Feature request
Held for next release cycle
High Priority
Low Priority
Medium Priority
Minor change
Translation/Locale
WIP
No milestone
No project
No assignees
3 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: AkkomaGang/akkoma-fe#354
Loading…
Reference in a new issue
No description provided.
Delete branch "smitten/akkoma-fe:date-locale-fix-cherrypick"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Dates are formatted with the currently configured i18n locale code, but those locales discard the country code from the language. So both
en-US
anden-GB
in the browser settings are mapped toen
in the i18n messages.This results in dates being formatted in USian MM/DD/YYYY format instead of DD/MM/YYYY format as expected. See post from 0w0.is.
This PR does not affect the i18n mapping but updates
internalToBrowserLocale
so it checks what is set on window.navigator before falling back to the i18n value.Not an Akkoma maintainer, so don't take my suggestion as having any weight.
Getting rid of the forced US format for English is good, but I feel like the current approach creates a new problem.
It will entirely discard the interface language selected in the frontend settings in favour of the primary browser locale. But those two might intentionally differ resulting in e.g. dates being formatted in a way not matching any variant of the FE language.
Imho it would be better to use the browser languages to select the highest prio entry matching the FE language. If there’s no matching browser language, we’ll still have to fallback to the regionless FE language, but in that case it seems fair to assume the user doesn't care about the particular variant (or there might be no regional variants. Anyway they can easily fix it by adding an entry to their browser’s languages).
I.e. updating the patch to something like this:
Note: on page load
internalToBackendLocale
is called once for all existing localisations and after that only for the configured FE language, but apparently each time something gets rendered into HTML.Not sure if this repeated looping over
windows.navigator.languages
is a significant cost, but if so, it might be better to cache the results of the initial queries somewhere.@Oneric that makes sense to me, updated with those changes and I did do the cache too, might as well since it runs in render.
this PR made me realise that my VM was using US english the whole time i was using it.. i legit did not realise, and now it can format in UK english
this works! thanks