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

[#66093] Translate error messages

Tobias Dillmannc32c5d70d3ed
diff --git a/app/models/calculated_value_error.rb b/app/models/calculated_value_error.rb
index 56ad78af475..4c0515c246d 100644
--- a/app/models/calculated_value_error.rb
+++ b/app/models/calculated_value_error.rb
@@ -32,9 +32,11 @@ class CalculatedValueError < ApplicationRecord
belongs_to :project
belongs_to :custom_field
- VALID_ERROR_CODES = %w[
- ERROR_MATHEMATICAL
- ].freeze
+ ERROR_TRANSLATIONS = {
+ "ERROR_MATHEMATICAL" => "calculated_values.errors.mathematical"
+ }.freeze
+
+ VALID_ERROR_CODES = ERROR_TRANSLATIONS.keys.freeze
validates :project_id, presence: true
validates :custom_field_id, presence: true
@@ -42,6 +44,8 @@ class CalculatedValueError < ApplicationRecord
validates :error_code, inclusion: { in: VALID_ERROR_CODES }
def error_message
- "TODO: humanize error code into a nice, translated error message"
+ translation_key = ERROR_TRANSLATIONS.fetch(error_code, "calculated_values.errors.unknown")
+
+ I18n.t(translation_key)
end
end
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 7d112f89d4f..6a1d79be5df 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -360,6 +360,11 @@ en:
no_results_title_text: There are currently no custom fields.
no_results_content_text: Create a new custom field
+ calculated_values:
+ errors:
+ unknown: "An unknown error occurred during calculation. Please review the formula and try again."
+ mathematical: "A mathematical error occurred. Please review the formula and try again."
+
concatenation:
single: "or"