Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Review feedback

Oliver Günther55a47c9ae029
diff --git a/app/models/custom_fields_project.rb b/app/models/custom_fields_project.rb
index a16ca3a670f..402c7c58405 100644
--- a/app/models/custom_fields_project.rb
+++ b/app/models/custom_fields_project.rb
@@ -30,10 +30,4 @@
class CustomFieldsProject < ApplicationRecord
belongs_to :project
belongs_to :custom_field
-
- def self.human_attribute_name(attribute, options = {})
- {
- project_ids: "#{Project.model_name.human} IDs"
- }[attribute] || super
- end
end
diff --git a/app/models/project_custom_field_project_mapping.rb b/app/models/project_custom_field_project_mapping.rb
index aaccbe9679c..4836280fb95 100644
--- a/app/models/project_custom_field_project_mapping.rb
+++ b/app/models/project_custom_field_project_mapping.rb
@@ -32,10 +32,4 @@ class ProjectCustomFieldProjectMapping < ApplicationRecord
inverse_of: :project_custom_field_project_mappings
validates :custom_field_id, uniqueness: { scope: :project_id }
-
- def self.human_attribute_name(attribute, options = {})
- {
- project_ids: "#{Project.model_name.human} IDs"
- }[attribute] || super
- end
end
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 1c46f0b685e..bb9c87e7b56 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -1671,6 +1671,7 @@ en:
password: "Password"
priority: "Priority"
project: "Project"
+ project_ids: "Project IDs"
reason: "Reason"
responsible: "Accountable"
required: "Required"
diff --git a/lib/open_project/patches/active_record_i18n.rb b/lib/open_project/patches/active_record_i18n.rb
index e9b508d3766..cc0beab8a76 100644
--- a/lib/open_project/patches/active_record_i18n.rb
+++ b/lib/open_project/patches/active_record_i18n.rb
@@ -35,7 +35,7 @@ module ActiveRecord
def self.human_attribute_name(attr, options = {})
attr = attr.to_s.delete_suffix("_id")
- options[:default] ||= I18n.t("activerecord.models.#{attr}", count: 1, default: nil)
+ options[:default] ||= :"activerecord.models.#{attr}"
if Rails.env.local?
def attr.humanize(*)
diff --git a/modules/storages/app/models/storages/project_storage.rb b/modules/storages/app/models/storages/project_storage.rb
index 3c65bcc9c96..6d33c1b2942 100644
--- a/modules/storages/app/models/storages/project_storage.rb
+++ b/modules/storages/app/models/storages/project_storage.rb
@@ -57,12 +57,6 @@ module Storages
.where(storage: Storage.automatic_management_enabled)
end
- def self.human_attribute_name(attribute, options = {})
- {
- project_ids: "#{Project.model_name.human} IDs"
- }[attribute] || super
- end
-
def project_folder_mode_possible?(project_folder_mode)
storage.present? && storage.available_project_folder_modes&.include?(project_folder_mode)
end
diff --git a/spec/lib/i18n/human_attribute_name_spec.rb b/spec/lib/i18n/human_attribute_name_spec.rb
index a6f2b4b171c..5d9d38e5790 100644
--- a/spec/lib/i18n/human_attribute_name_spec.rb
+++ b/spec/lib/i18n/human_attribute_name_spec.rb
@@ -41,6 +41,10 @@ RSpec.describe "I18n human_attribute_name", type: :helper do
end
it "returns a valid translation for basic attribute" do
+ # looks up "activerecord.attributes.test_model.name", "attributes.name",
+ # and "activerecord.models.name" i18n keys
+ # "activerecord.attributes.test_model.name" i18n key does not exist
+ # "attributes.name" i18n key exists and translates to "Name"
expect(test_model.human_attribute_name("name")).to eq "Name"
end
@@ -48,4 +52,9 @@ RSpec.describe "I18n human_attribute_name", type: :helper do
expect { test_model.human_attribute_name("weird_attribute_that_does_not_exist") }
.to raise_error(/I18n translation missing for attribute weird/)
end
+
+ it "returns a valid translation for a model name if corresponding i18n key activerecord.models.<attribute> exists" do
+ # looks up "activerecord.models.project" i18n key
+ expect(test_model.human_attribute_name("project")).to eq "Project"
+ end
end