Skip to content

fix: handle missing category translations gracefully#830

Open
rewritten wants to merge 2 commits intocoopdevs:developfrom
rewritten:fix/829-category-nil-name
Open

fix: handle missing category translations gracefully#830
rewritten wants to merge 2 commits intocoopdevs:developfrom
rewritten:fix/829-category-nil-name

Conversation

@rewritten
Copy link
Contributor

Summary

  • Fixes Manually creating new category breaks timebank admin #829: crash when viewing offers/needs after creating a category with a non-default locale
  • Adds Category#display_name that falls back to any available translation when the current locale's name is nil or blank
  • Appends [locale] to the displayed name when a fallback is used, so it's clear the name comes from another language
  • Updates views and helper to use display_name instead of name directly

Test plan

  • Create a category with locale=NL without filling in a name
  • Switch to locale=EN and visit /offers — no crash, category appears with [nl] suffix if it has a Dutch name, or is sorted to top if truly empty
  • Create a category with a name in one locale, verify it shows with [locale] indicator when viewed in a different locale

🤖 Generated with Claude Code

)

Add display_name to Category that falls back to any available translation
when the current locale's name is nil or blank, appending [locale] to
indicate the language it came from. Fixes crash in all_categories sort
when a category is created without a translation for the current locale.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings March 26, 2026 12:21
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a safer way to render category names when the current locale’s translation is missing, preventing crashes in category filter rendering/sorting.

Changes:

  • Introduces Category#display_name with a fallback to any available translated name (with a locale indicator).
  • Updates shared filter partials to use display_name instead of name.
  • Adjusts category sorting in CategoriesHelper#all_categories to rely on to_s.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
app/models/category.rb Adds display_name fallback logic and updates to_s to use it.
app/helpers/categories_helper.rb Changes category sorting to use to_s for downcasing/sorting.
app/views/shared/_show_filter_hint.html.erb Renders the current category via display_name.
app/views/shared/_post_filters.html.erb Uses display_name in the category dropdown and items.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

… string

- Fall back to Category.model_name.human when no translations exist at all
- Use display_name explicitly in helper sort to make crash-safety clear
- Use display_name in views for consistent fallback display

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Manually creating new category breaks timebank admin

2 participants