-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Set user's 24h preference from their current OS locale #29651
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
Fixes: #28371
Edit: Comment below is not accurate anymore, see #29651 (comment) for solution.
--
relative-time
uses the closestlang
attribute 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-US
as 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: