-
Notifications
You must be signed in to change notification settings - Fork 122
feat(i18n): add Italian locale (it) #396
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
base: main
Are you sure you want to change the base?
Changes from all commits
5206ac9
01cf179
4b81d9f
13df6ce
5bf91bf
ae2534b
524bcce
75168af
c41a7f2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,28 +11,19 @@ class InvalidKeyError < StandardError; end | |
|
|
||
| PERIODS = { | ||
| "last_day" => { | ||
| date_range: -> { [ 1.day.ago.to_date, Date.current ] }, | ||
| label_short: "1D", | ||
| label: "Last Day", | ||
| comparison_label: "vs. yesterday" | ||
| date_range: -> { [ 1.day.ago.to_date, Date.current ] } | ||
| }, | ||
| "current_week" => { | ||
| date_range: -> { [ Date.current.beginning_of_week, Date.current ] }, | ||
| label_short: "WTD", | ||
| label: "Current Week", | ||
| comparison_label: "vs. start of week" | ||
| date_range: -> { [ Date.current.beginning_of_week, Date.current ] } | ||
| }, | ||
| "last_7_days" => { | ||
| date_range: -> { [ 7.days.ago.to_date, Date.current ] }, | ||
| label_short: "7D", | ||
| label: "Last 7 Days", | ||
| comparison_label: "vs. last week" | ||
| date_range: -> { [ 7.days.ago.to_date, Date.current ] } | ||
| }, | ||
| "current_month" => { | ||
| date_range: -> { [ Date.current.beginning_of_month, Date.current ] }, | ||
| label_short: "MTD", | ||
| label: "Current Month", | ||
| comparison_label: "vs. start of month" | ||
| date_range: -> { [ Date.current.beginning_of_month, Date.current ] } | ||
| }, | ||
| "last_month" => { | ||
| date_range: -> { [ 1.month.ago.beginning_of_month.to_date, 1.month.ago.end_of_month.to_date ] } | ||
| }, | ||
| "last_month" => { | ||
| date_range: -> { [ 1.month.ago.beginning_of_month.to_date, 1.month.ago.end_of_month.to_date ] }, | ||
|
|
@@ -47,53 +38,32 @@ class InvalidKeyError < StandardError; end | |
| comparison_label: "vs. last 30 days" | ||
| }, | ||
| "last_90_days" => { | ||
| date_range: -> { [ 90.days.ago.to_date, Date.current ] }, | ||
| label_short: "90D", | ||
| label: "Last 90 Days", | ||
| comparison_label: "vs. last quarter" | ||
| date_range: -> { [ 90.days.ago.to_date, Date.current ] } | ||
| }, | ||
| "current_year" => { | ||
| date_range: -> { [ Date.current.beginning_of_year, Date.current ] }, | ||
| label_short: "YTD", | ||
| label: "Current Year", | ||
| comparison_label: "vs. start of year" | ||
| date_range: -> { [ Date.current.beginning_of_year, Date.current ] } | ||
| }, | ||
| "last_365_days" => { | ||
| date_range: -> { [ 365.days.ago.to_date, Date.current ] }, | ||
| label_short: "365D", | ||
| label: "Last 365 Days", | ||
| comparison_label: "vs. 1 year ago" | ||
| date_range: -> { [ 365.days.ago.to_date, Date.current ] } | ||
| }, | ||
| "last_5_years" => { | ||
| date_range: -> { [ 5.years.ago.to_date, Date.current ] }, | ||
| label_short: "5Y", | ||
| label: "Last 5 Years", | ||
| comparison_label: "vs. 5 years ago" | ||
| date_range: -> { [ 5.years.ago.to_date, Date.current ] } | ||
| }, | ||
| "last_10_years" => { | ||
| date_range: -> { [ 10.years.ago.to_date, Date.current ] }, | ||
| label_short: "10Y", | ||
| label: "Last 10 Years", | ||
| comparison_label: "vs. 10 years ago" | ||
| date_range: -> { [ 10.years.ago.to_date, Date.current ] } | ||
| }, | ||
| "all_time" => { | ||
| date_range: -> { | ||
| oldest_date = Current.family&.oldest_entry_date | ||
| # If no family or no entries exist, use a reasonable historical fallback | ||
| # to ensure "All Time" represents a meaningful range, not just today | ||
| start_date = if oldest_date && oldest_date < Date.current | ||
| oldest_date | ||
| else | ||
| 5.years.ago.to_date | ||
| end | ||
| [ start_date, Date.current ] | ||
| }, | ||
| label_short: "All", | ||
| label: "All Time", | ||
| comparison_label: "vs. beginning" | ||
| } | ||
| } | ||
| } | ||
|
|
||
| class << self | ||
| def from_key(key) | ||
| unless PERIODS.key?(key) | ||
|
|
@@ -156,28 +126,23 @@ def interval | |
| end | ||
| end | ||
|
|
||
| def i18n_scope | ||
| "periods.#{key}" | ||
| end | ||
|
Comment on lines
+129
to
+131
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Guard against nil key for cleaner i18n lookups. When Consider adding a guard: def i18n_scope
- "periods.#{key}"
+ key ? "periods.#{key}" : nil
endThen update the label methods to skip i18n lookup when i18n_scope is nil: def label
- I18n.t("#{i18n_scope}.label", default: "Custom Period")
+ return "Custom Period" unless i18n_scope
+ I18n.t("#{i18n_scope}.label", default: "Custom Period")
end(Apply similar changes to
🤖 Prompt for AI Agents |
||
|
|
||
| def label | ||
| if key_metadata | ||
| key_metadata.fetch(:label) | ||
| else | ||
| "Custom Period" | ||
| end | ||
| I18n.t("#{i18n_scope}.label", default: "Custom Period") | ||
| end | ||
|
|
||
| def label_short | ||
| if key_metadata | ||
| key_metadata.fetch(:label_short) | ||
| else | ||
| "Custom" | ||
| end | ||
| I18n.t("#{i18n_scope}.label_short", default: "Custom") | ||
| end | ||
|
|
||
| def comparison_label | ||
| if key_metadata | ||
| key_metadata.fetch(:comparison_label) | ||
| else | ||
| "#{start_date.strftime(@date_format)} to #{end_date.strftime(@date_format)}" | ||
| end | ||
| I18n.t( | ||
| "#{i18n_scope}.comparison_label", | ||
| default: "#{start_date.strftime(@date_format)} to #{end_date.strftime(@date_format)}" | ||
| ) | ||
| end | ||
|
|
||
| private | ||
|
|
||
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.
Bug: Duplicate "last_month" key in PERIODS hash
The
PERIODShash contains two entries with the key"last_month". Ruby hashes don't support duplicate keys, so the second entry will silently overwrite the first. This appears to be an incomplete refactoring where a new entry was added (lines 24-27) but the old entry (lines 28-33 with inline labels) wasn't removed. The second duplicate still contains hardcoded labels that should have been removed as part of the i18n migration.