Commit 8d8e2173 authored by Sean McGivern's avatar Sean McGivern

Merge branch '207834-add-missing-internationalization-support-to-error-messages' into 'master'

Add internationalization support to error messages [Part 1]

See merge request gitlab-org/gitlab!25819
parents e662ccf0 b335cb9c
......@@ -38,7 +38,7 @@ class Appearance < ApplicationRecord
def single_appearance_row
if self.class.any?
errors.add(:single_appearance_row, 'Only 1 appearances row can exist')
errors.add(:base, _('Only 1 appearances row can exist'))
end
end
......
......@@ -389,7 +389,7 @@ module ApplicationSettingImplementation
def terms_exist
return unless enforce_terms?
errors.add(:terms, "You need to set terms to be enforced") unless terms.present?
errors.add(:base, _('You need to set terms to be enforced')) unless terms.present?
end
def expire_performance_bar_allowed_user_ids_cache
......
......@@ -148,7 +148,7 @@ module Ci
def valid_file_format?
unless TYPE_AND_FORMAT_PAIRS[self.file_type&.to_sym] == self.file_format&.to_sym
errors.add(:file_format, 'Invalid file format with specified file type')
errors.add(:base, _('Invalid file format with specified file type'))
end
end
......
......@@ -306,7 +306,7 @@ module Clusters
.where.not(id: id)
if duplicate_management_clusters.any?
errors.add(:environment_scope, "cannot add duplicated environment scope")
errors.add(:environment_scope, 'cannot add duplicated environment scope')
end
end
......@@ -380,7 +380,7 @@ module Clusters
def restrict_modification
if provider&.on_creation?
errors.add(:base, "cannot modify during creation")
errors.add(:base, _('Cannot modify provider during creation'))
return false
end
......
......@@ -19,7 +19,7 @@ module HasRepository
def valid_repo?
repository.exists?
rescue
errors.add(:path, _('Invalid repository path'))
errors.add(:base, _('Invalid repository path'))
false
end
......
......@@ -37,7 +37,7 @@ module Milestoneable
private
def milestone_is_valid
errors.add(:milestone_id, message: "is invalid") if respond_to?(:milestone_id) && milestone_id.present? && !milestone_available?
errors.add(:milestone_id, 'is invalid') if respond_to?(:milestone_id) && milestone_id.present? && !milestone_available?
end
end
......
......@@ -77,7 +77,7 @@ module TimeTrackable
return if time_spent.nil? || time_spent == :reset
if time_spent < 0 && (time_spent.abs > original_total_time_spent)
errors.add(:time_spent, 'Time to subtract exceeds the total time spent')
errors.add(:base, _('Time to subtract exceeds the total time spent'))
end
end
......
......@@ -105,7 +105,7 @@ class DeployToken < ApplicationRecord
end
def ensure_at_least_one_scope
errors.add(:base, "Scopes can't be blank") unless read_repository || read_registry
errors.add(:base, _("Scopes can't be blank")) unless read_repository || read_registry
end
def default_username
......
......@@ -19,7 +19,13 @@ class DescriptionVersion < ApplicationRecord
def exactly_one_issuable
issuable_count = self.class.issuable_attrs.count { |attr| self["#{attr}_id"] }
errors.add(:base, "Exactly one of #{self.class.issuable_attrs.join(', ')} is required") if issuable_count != 1
if issuable_count != 1
errors.add(
:base,
_("Exactly one of %{attributes} is required") %
{ attributes: self.class.issuable_attrs.join(', ') }
)
end
end
end
......
......@@ -78,7 +78,7 @@ class ExternalPullRequest < ApplicationRecord
def not_from_fork
if from_fork?
errors.add(:base, 'Pull requests from fork are not supported')
errors.add(:base, _('Pull requests from fork are not supported'))
end
end
......
......@@ -11,6 +11,6 @@ class MilestoneRelease < ApplicationRecord
def same_project_between_milestone_and_release
return if milestone&.project_id == release&.project_id
errors.add(:base, 'does not have the same project as the milestone')
errors.add(:base, _('Release does not have the same project as the milestone'))
end
end
......@@ -376,7 +376,7 @@ class Namespace < ApplicationRecord
def nesting_level_allowed
if ancestors.count > Group::NUMBER_OF_ANCESTORS_ALLOWED
errors.add(:parent_id, "has too deep level of nesting")
errors.add(:parent_id, 'has too deep level of nesting')
end
end
......
......@@ -168,7 +168,7 @@ class IssueTrackerService < Service
return if project.blank?
if project.services.external_issue_trackers.where.not(id: id).any?
errors.add(:base, 'Another issue tracker is already in use. Only one issue tracker service can be active at a time')
errors.add(:base, _('Another issue tracker is already in use. Only one issue tracker service can be active at a time'))
end
end
end
......
......@@ -69,13 +69,13 @@ class PrometheusAlert < ApplicationRecord
def require_valid_environment_project!
return if project == environment&.project
errors.add(:environment, "invalid project")
errors.add(:environment, 'invalid project')
end
def require_valid_metric_project!
return if prometheus_metric&.common?
return if project == prometheus_metric&.project
errors.add(:prometheus_metric, "invalid project")
errors.add(:prometheus_metric, 'invalid project')
end
end
......@@ -37,6 +37,9 @@ class ResourceEvent < ApplicationRecord
return true if issuable_count == 1
end
errors.add(:base, "Exactly one of #{self.class.issuable_attrs.join(', ')} is required")
errors.add(
:base, _("Exactly one of %{attributes} is required") %
{ attributes: self.class.issuable_attrs.join(', ') }
)
end
end
......@@ -111,7 +111,10 @@ class SentNotification < ApplicationRecord
note = create_reply('Test', dryrun: true)
unless note.valid?
self.errors.add(:base, "Note parameters are invalid: #{note.errors.full_messages.to_sentence}")
self.errors.add(
:base, _("Note parameters are invalid: %{errors}") %
{ errors: note.errors.full_messages.to_sentence }
)
end
end
......
......@@ -28,9 +28,9 @@ class Timelog < ApplicationRecord
def issuable_id_is_present
if issue_id && merge_request_id
errors.add(:base, 'Only Issue ID or Merge Request ID is required')
errors.add(:base, _('Only Issue ID or Merge Request ID is required'))
elsif issuable.nil?
errors.add(:base, 'Issue or Merge Request ID is required')
errors.add(:base, _('Issue or Merge Request ID is required'))
end
end
......
......@@ -108,13 +108,13 @@ module DesignManagement
return if id_a == id_b
errors.add(:issue, "must be the same on design and version")
errors.add(:issue, 'must be the same on design and version')
end
def design_and_version_have_issue_id
return if [design, version].all? { |obj| obj.try(:issue_id).present? }
errors.add(:issue, "must be present on both design and version")
errors.add(:issue, 'must be present on both design and version')
end
end
end
......@@ -310,7 +310,7 @@ module EE
return if custom_project_templates_group_id.blank?
return if children.exists?(id: custom_project_templates_group_id)
errors.add(:custom_project_templates_group_id, "has to be a subgroup of the group")
errors.add(:custom_project_templates_group_id, 'has to be a subgroup of the group')
end
def billed_group_members
......
......@@ -71,7 +71,7 @@ module EE
def validate_managing_group
return unless saml_provider&.enforced_group_managed_accounts?
errors.add(:base, 'Group requires separate account') if saml_provider.group != user.managing_group
errors.add(:base, _('Group requires separate account')) if saml_provider.group != user.managing_group
end
end
end
......@@ -131,7 +131,7 @@ module EE
def cannot_be_admin_and_auditor
if admin? && auditor?
errors.add(:admin, "user cannot also be an Auditor.")
errors.add(:admin, 'user cannot also be an Auditor.')
end
end
......
......@@ -343,14 +343,14 @@ class GeoNode < ApplicationRecord
# Prevent locking yourself out
def require_current_node_to_be_primary
if name == self.class.current_node_name
errors.add(:base, 'Current node must be the primary node or you will be locking yourself out')
errors.add(:base, _('Current node must be the primary node or you will be locking yourself out'))
end
end
# Prevent creating a Geo Node unless Hashed Storage is enabled
def require_hashed_storage
unless Gitlab::CurrentSettings.hashed_storage_enabled?
errors.add(:base, 'Hashed Storage must be enabled to use Geo')
errors.add(:base, _('Hashed Storage must be enabled to use Geo'))
end
end
......
......@@ -476,7 +476,7 @@ class License < ApplicationRecord
def valid_license
return if license?
self.errors.add(:base, "The license key is invalid. Make sure it is exactly as you received it from GitLab Inc.")
self.errors.add(:base, _('The license key is invalid. Make sure it is exactly as you received it from GitLab Inc.'))
end
def prior_historical_max
......@@ -542,6 +542,6 @@ class License < ApplicationRecord
def not_expired
return unless self.license? && self.expired?
self.errors.add(:base, "This license has already expired.")
self.errors.add(:base, _('This license has already expired.'))
end
end
......@@ -35,7 +35,7 @@ class Packages::ConanMetadatum < ApplicationRecord
def conan_package_type
unless package && package.conan?
errors.add(:base, 'Package type must be Conan')
errors.add(:base, _('Package type must be Conan'))
end
end
end
......@@ -22,7 +22,7 @@ class Packages::MavenMetadatum < ApplicationRecord
def maven_package_type
unless package && package.maven?
errors.add(:base, 'Package type must be Maven')
errors.add(:base, _('Package type must be Maven'))
end
end
end
......@@ -125,7 +125,7 @@ class Packages::Package < ApplicationRecord
.id_not_in(id)
.exists?
errors.add(:base, 'Package recipe already exists') if recipe_exists
errors.add(:base, _('Package recipe already exists')) if recipe_exists
end
def valid_npm_package_name
......@@ -140,7 +140,7 @@ class Packages::Package < ApplicationRecord
return unless project
if project.package_already_taken?(name)
errors.add(:base, 'Package already exists')
errors.add(:base, _('Package already exists'))
end
end
end
......@@ -25,7 +25,7 @@ class ServiceDeskSetting < ApplicationRecord
def valid_issue_template
if issue_template_missing?
errors.add(:issue_template_key, "is empty or does not exist")
errors.add(:issue_template_key, 'is empty or does not exist')
end
end
end
......@@ -12,14 +12,14 @@ module DraftNotes
def execute
if in_reply_to_discussion_id.present?
unless discussion
return base_error('Thread to reply to cannot be found')
return base_error(_('Thread to reply to cannot be found'))
end
params[:discussion_id] = discussion.reply_id
end
if params[:resolve_discussion] && !can_resolve_discussion?
return base_error('User is not allowed to resolve thread')
return base_error(_('User is not allowed to resolve thread'))
end
draft_note = DraftNote.new(params)
......
......@@ -2015,6 +2015,9 @@ msgstr ""
msgid "Anonymous"
msgstr ""
msgid "Another issue tracker is already in use. Only one issue tracker service can be active at a time"
msgstr ""
msgid "Anti-spam verification"
msgstr ""
......@@ -3251,6 +3254,9 @@ msgstr ""
msgid "Cannot modify managed Kubernetes cluster"
msgstr ""
msgid "Cannot modify provider during creation"
msgstr ""
msgid "Cannot refer to a group milestone by an internal id!"
msgstr ""
......@@ -5820,6 +5826,9 @@ msgstr ""
msgid "Current node"
msgstr ""
msgid "Current node must be the primary node or you will be locking yourself out"
msgstr ""
msgid "Current password"
msgstr ""
......@@ -8021,6 +8030,9 @@ msgstr ""
msgid "Evidence collection"
msgstr ""
msgid "Exactly one of %{attributes} is required"
msgstr ""
msgid "Example: @sub\\.company\\.com$"
msgstr ""
......@@ -9779,6 +9791,9 @@ msgstr ""
msgid "Group pipeline minutes were successfully reset."
msgstr ""
msgid "Group requires separate account"
msgstr ""
msgid "Group variables (inherited)"
msgstr ""
......@@ -10124,6 +10139,9 @@ msgstr ""
msgid "HTTP Basic: Access denied\\nYou must use a personal access token with 'api' scope for Git over HTTP.\\nYou can generate one at %{profile_personal_access_tokens_url}"
msgstr ""
msgid "Hashed Storage must be enabled to use Geo"
msgstr ""
msgid "Hashed repository storage paths"
msgstr ""
......@@ -10758,6 +10776,9 @@ msgstr ""
msgid "Invalid field"
msgstr ""
msgid "Invalid file format with specified file type"
msgstr ""
msgid "Invalid file."
msgstr ""
......@@ -10851,6 +10872,9 @@ msgstr ""
msgid "Issue events"
msgstr ""
msgid "Issue or Merge Request ID is required"
msgstr ""
msgid "Issue template (optional)"
msgstr ""
......@@ -13147,6 +13171,9 @@ msgstr ""
msgid "Note"
msgstr ""
msgid "Note parameters are invalid: %{errors}"
msgstr ""
msgid "Note that this invitation was sent to %{mail_to_invite_email}, but you are signed in as %{link_to_current_user} with email %{mail_to_current_user}."
msgstr ""
......@@ -13380,6 +13407,12 @@ msgstr ""
msgid "Only 'Reporter' roles and above on tiers Premium / Silver and above can see Value Stream Analytics."
msgstr ""
msgid "Only 1 appearances row can exist"
msgstr ""
msgid "Only Issue ID or Merge Request ID is required"
msgstr ""
msgid "Only Project Members"
msgstr ""
......@@ -13554,12 +13587,24 @@ msgstr ""
msgid "Package Registry"
msgstr ""
msgid "Package already exists"
msgstr ""
msgid "Package deleted successfully"
msgstr ""
msgid "Package information"
msgstr ""
msgid "Package recipe already exists"
msgstr ""
msgid "Package type must be Conan"
msgstr ""
msgid "Package type must be Maven"
msgstr ""
msgid "Package was removed"
msgstr ""
......@@ -15759,6 +15804,9 @@ msgstr ""
msgid "Pull"
msgstr ""
msgid "Pull requests from fork are not supported"
msgstr ""
msgid "Puma is running with a thread count above 1 and the Rugged service is enabled. This may decrease performance in some environments. See our %{link_start}documentation%{link_end} for details of this issue."
msgstr ""
......@@ -16021,6 +16069,9 @@ msgid_plural "Releases"
msgstr[0] ""
msgstr[1] ""
msgid "Release does not have the same project as the milestone"
msgstr ""
msgid "Release notes"
msgstr ""
......@@ -16840,6 +16891,9 @@ msgstr ""
msgid "Scopes"
msgstr ""
msgid "Scopes can't be blank"
msgstr ""
msgid "Scroll down"
msgstr ""
......@@ -19358,6 +19412,9 @@ msgstr ""
msgid "The issue stage shows the time it takes from creating an issue to assigning the issue to a milestone, or add the issue to a list on your Issue Board. Begin creating issues to see data for this stage."
msgstr ""
msgid "The license key is invalid. Make sure it is exactly as you received it from GitLab Inc."
msgstr ""
msgid "The license was removed. GitLab has fallen back on the previous license."
msgstr ""
......@@ -20012,6 +20069,9 @@ msgstr ""
msgid "This job will automatically run after its timer finishes. Often they are used for incremental roll-out deploys to production environments. When unscheduled it converts into a manual action."
msgstr ""
msgid "This license has already expired."
msgstr ""
msgid "This may expose confidential information as the selected fork is in another namespace that can have other members."
msgstr ""
......@@ -20123,6 +20183,9 @@ msgstr ""
msgid "Those emails automatically become issues (with the comments becoming the email conversation) listed here."
msgstr ""
msgid "Thread to reply to cannot be found"
msgstr ""
msgid "Threat Monitoring"
msgstr ""
......@@ -20219,6 +20282,9 @@ msgstr ""
msgid "Time to merge"
msgstr ""
msgid "Time to subtract exceeds the total time spent"
msgstr ""
msgid "Time tracking"
msgstr ""
......@@ -21297,6 +21363,9 @@ msgstr ""
msgid "User identity was successfully updated."
msgstr ""
msgid "User is not allowed to resolve thread"
msgstr ""
msgid "User key was successfully removed."
msgstr ""
......@@ -22612,6 +22681,9 @@ msgstr ""
msgid "You need to register a two-factor authentication app before you can set up a U2F device."
msgstr ""
msgid "You need to set terms to be enforced"
msgstr ""
msgid "You need to specify both an Access Token and a Host URL."
msgstr ""
......
......@@ -86,7 +86,7 @@ describe Clusters::UpdateService do
it 'rejects changes' do
is_expected.to eq(false)
expect(cluster.errors.full_messages).to include('cannot modify during creation')
expect(cluster.errors.full_messages).to include('Cannot modify provider during creation')
end
end
end
......
......@@ -109,7 +109,7 @@ RSpec.shared_examples 'time tracking endpoints' do |issuable_name|
end
expect(response).to have_gitlab_http_status(:bad_request)
expect(json_response['message']['time_spent'].first).to match(/exceeds the total time spent/)
expect(json_response['message']['base'].first).to eq(_('Time to subtract exceeds the total time spent'))
end
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment