Set user's 24h preference from their current OS locale#29651
Set user's 24h preference from their current OS locale#29651lunny merged 21 commits intogo-gitea:mainfrom
Conversation
denyskon
left a comment
There was a problem hiding this comment.
Well it isn't pretty, but technically it's the correct solution 😆
|
Basically I take it as our fault for setting |
<relative-time> with user's current locale settings<relative-time> with user's current locale
|
Wouldn't that affect date display language to differ from UI? |
<relative-time> with user's current locale|
Ready now. I think I will also upstream this fix into https://github.com/github/relative-time-element, because honestly I'm also tired of seeing the 12h format on GitHub. 😆 |
|
I'll try do one more enhancement to detect availability of |
Actually, no, I won't do it. The relevant Intl API usage is too hackish, maybe revisit this in a few years once they have introduced proper usable APIs. const props = {};
const intlLocale = new Intl.Locale(Intl.DateTimeFormat().resolvedOptions().locale);
const hourCycle = intlLocale.getHourCycles?.()[0] ?? intlLocale.hourCycles?.[0];
if (hourCycle) {
props.hourCycle = hourCycle;
} else {
props.hour12 = !Number.isInteger(Number(new Intl.DateTimeFormat([], {hour: 'numeric'}).format()));
} |
Fixes: #28371 Fixed by using a JS solution that formats according to `lang`, but alters the 24h format setting as per user's locale. This will work for all tooltips: <img width="243" alt="Screenshot 2024-03-07 at 23 03 35" src="https://github.com/go-gitea/gitea/assets/115237/6d16c71c-6786-4eda-8cdc-50ec68ba62c6"> <img width="250" alt="Screenshot 2024-03-07 at 23 03 17" src="https://github.com/go-gitea/gitea/assets/115237/4e26bbb7-12df-4b81-bd37-14705e87e8f7"> <img width="310" alt="Screenshot 2024-03-07 at 23 14 34" src="https://github.com/go-gitea/gitea/assets/115237/1ef599f0-6401-4e19-b1da-59cdfc09b0f6"> I think there is only one other place in the UI where we render such absolute dates, which is in the actions view and which I've also fixed: <img width="275" alt="Screenshot 2024-03-07 at 23 04 00" src="https://github.com/go-gitea/gitea/assets/115237/df0fbe1f-96ee-4338-ab5e-2b10e215005d">
|
Sorry for the mistake of the commit message and I have to amend the commit message with magic power. |
* giteaofficial/main: Add cache for branch divergence on branch list page (go-gitea#29577) Fix user-defined markup links targets (go-gitea#29305) Don't show AbortErrors on logout (go-gitea#29639) Style fomantic grey labels (go-gitea#29458) Don't use `<br />` in alert block (go-gitea#29650) Fix incorrect rendering csv file when file size is larger than UI.CSV.MaxFileSize (go-gitea#29653) Set user's 24h preference from their current OS locale (go-gitea#29651) Move get/set default branch from git package to gitrepo package to hide repopath (go-gitea#29126) Make runs-on support variable expression (go-gitea#29468)
|
Upstream issue: github/relative-time-element#276 |
|
Note for future: This workaround can be removed once github/relative-time-element#329 is merged and released. If there is no progress on that, I will fork the repo. |





Fixes: #28371
Edit: Comment below is not accurate anymore, see #29651 (comment) for solution.
--
relative-timeuses the closestlangattribute to format dates, but the problem our closest tag is on<html>which does contain the the selected locale for the UI, which may not necessarly match the user's currently locale.For example any user with 24h clock preference that has set
en-USas their language in gitea will receive US-based 12h formatting. To achieve locale-specific time formatting, setlang=unknown(the default value oflang) on<relative-time>which results in locale-aware formatting and likely a small speedup because the element does not have to search up the whole HTML tree.Before:

After:
