Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/helpers/categories_helper.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module CategoriesHelper
def all_categories
@all_categories ||= Category.all.sort_by { |a| a.name.downcase }
@all_categories ||= Category.all.sort_by { |a| a.display_name.downcase }
end

def categories_for_select
Expand Down
11 changes: 10 additions & 1 deletion app/models/category.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,16 @@ class Category < ApplicationRecord

translates :name

def display_name
return name if name.present?

fallback_locale, fallback_name = name_translations&.find { |_, v| v.present? }
return "#{fallback_name} [#{fallback_locale}]" if fallback_name.present?

self.class.model_name.human
end

def to_s
name
display_name
end
end
4 changes: 2 additions & 2 deletions app/views/shared/_post_filters.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<ul class="nav navbar-nav d-none d-sm-flex">
<li class="dropdown nav-item">
<a class="dropdown-toggle nav-link text-primary" href="#" data-bs-toggle="dropdown" role="button" aria-expanded="false">
<%= @category ? @category.name : Category.model_name.human %>
<%= @category ? @category.display_name : Category.model_name.human %>
</a>
<ul class="dropdown-menu" role="menu">
<li>
Expand All @@ -30,7 +30,7 @@
<li>
<%= link_to "#{base_path}?cat=#{c.id}", class: "dropdown-item" do %>
<%= category_icon(c) %>
<%= c.name %>
<%= c.display_name %>
<% end %>
</li>
<% end %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/shared/_show_filter_hint.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<% if @category.present? %>
<small>
<%= glyph :category %>
<%= @category.name %>
<%= @category.display_name %>
</small>
<% end %>
<% if params[:q].present? %>
Expand Down
Loading