calendar: added support for custom calendar strings, and starting days - #2548
calendar: added support for custom calendar strings, and starting days#2548xrtxn wants to merge 1 commit into
Conversation
|
Hi, |
## Summary - upgrade to rust-i18n 4.2.0 and register Story locales with `extend!(gpui_component)` - add French Calendar and DatePicker translations as a Story-only extension - keep the component’s built-in Italian and Traditional Chinese locales unchanged - add French to the Story language menu and cover extension fallback behavior with a test - document custom I18n setup, namespace rules, override priority, and locale selection in English and Simplified Chinese This uses rust-i18n’s locale extension mechanism to address the customization requirement discussed in #2548 without adding every downstream locale to gpui-component itself. Refs #2548 ## Test Plan - `cargo test -p gpui-component-story` - `git diff --check` - `bun run build` *(blocked by the current Bun/Vite Vue runtime: `crypto.hash is not a function` while compiling the existing `contributors.md`)* --------- Co-authored-by: Codex <codex@openai.com>
|
Thanks, this should work for me, this was my original idea too, but unsure how to implement it. However, please check out .first_day_of_week() as well, as this is still missing. If you rather I can implement the changes needed for this updated version, |
|
first_day_of_week is ok to merge, you can cleanup you PR, then I will merge it. |
|
Please check it out, I cleaned up the code |
There was a problem hiding this comment.
Thanks for this! The grid math for the start day is correct, and it stays backward-compatible for the default (Sunday).
One blocking issue: the weekday header row isn't reordered, so any first_day_of_week other than Sun makes the whole calendar misaligned.
In render_days (calendar.rs) the header is a fixed Sunday-first list and is rendered in that order regardless of the start day:
let weeks = [t!("Calendar.week.0") /*Sun*/, ..., t!("Calendar.week.6") /*Sat*/];
// weeks.iter().map(render_week) // always Sun -> SatBut days() now shifts the date columns to start on first_day_of_week. So with first_day = Mon, column 0 shows the "Sun" header on top of Monday's dates.
Example - Feb 2023 (the 1st is a Wednesday), first_day = Mon:
- date columns become
Mon Tue Wed Thu Fri Sat Sun - header still renders
Sun Mon Tue ...-> off by one
Fix: rotate the weeks array by self.first_day_of_week.num_days_from_sunday() before rendering, using the same offset as the grid.
test_daysstill only checksWeekday::Sun. Please add aWeekday::Moncase so the offset is locked in.
Closes #2517
Description
Added support for custom weekday, month, and starting days. I found this to be the best tradeoff in terms of performance and ergonomy.
Screenshot
How to Test
First day
Week day and month day
Checklist
cargo runfor story tests related to the changes.