From ea7a230cb63d259f6dd452ccf80c3afb4d4199d0 Mon Sep 17 00:00:00 2001 From: Brian Cain Date: Tue, 19 Nov 2019 13:48:29 -0800 Subject: [PATCH] Move disk config validation messages to locales file --- plugins/kernel_v2/config/disk.rb | 18 ++++++++++++------ templates/locales/en.yml | 11 +++++++++++ 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/plugins/kernel_v2/config/disk.rb b/plugins/kernel_v2/config/disk.rb index ec4a57f92..fd33e7d12 100644 --- a/plugins/kernel_v2/config/disk.rb +++ b/plugins/kernel_v2/config/disk.rb @@ -121,28 +121,34 @@ module VagrantPlugins # validate type with list of known disk types if !DEFAULT_DISK_TYPES.include?(@type) - errors << "Disk type '#{@type}' is not a valid type. Please pick one of the following supported disk types: #{DEFAULT_DISK_TYPES.join(', ')}" + errors << I18n.t("vagrant.config.disk.invalid_type", type: @type, + types: DEFAULT_DISK_TYPES.join(', ')) end if @size && !@size.is_a?(Integer) if @size.is_a?(String) @size = Vagrant::Util::Numeric.string_to_bytes(@size) - else - errors << "Config option size for disk is not an integer" + end + + if !@size + errors << I18n.t("vagrant.config.disk.invalid_size", name: @name, machine: machine.name) end end if @file if !@file.is_a?(String) - errors << "Config option `file` for #{machine.name} disk config is not a string" + errors << I18n.t("vagrant.config.disk.invalid_file_type", file: @file, machine: machine.name) elsif !File.file?(@file) - errors << "Disk file '#{@file}' for disk '#{@name}' on machine '#{machine.name}' does not exist." + errors << I18n.t("vagrant.config.disk.missing_file", file_path: @file, + name: @name, machine: machine.name) end end if @provider_config if !@provider_config.keys.include?(machine.provider_name) - machine.env.ui.warn("Guest '#{machine.name}' using provider '#{machine.provider_name}' has provider specific config options for a provider other than '#{machine.provider_name}'. These provider config options will be ignored for this guest") + machine.env.ui.warn(I18n.t("vagrant.config.disk.missing_provider", + machine: machine.name, + provider_name: machine.provider_name)) end end diff --git a/templates/locales/en.yml b/templates/locales/en.yml index 2e78e01a6..3fa21f19a 100644 --- a/templates/locales/en.yml +++ b/templates/locales/en.yml @@ -1792,6 +1792,17 @@ en: # Translations for config validation errors #------------------------------------------------------------------------------- config: + disk: + invalid_type: |- + Disk type '%{type}' is not a valid type. Please pick one of the following supported disk types: %{types} + invalid_size: |- + Config option 'size' for disk '%{name}' on guest '%{machine}' is not an integer + invalid_file_type: |- + Disk config option 'file' for '%{machine}' is not a string. + missing_file: |- + Disk file '%{file_path}' for disk '%{name}' on machine '%{machine}' does not exist. + missing_provider: |- + Guest '%{machine}' using provider '%{provider_name}' has provider specific config options for a provider other than '%{provider_name}'. These provider config options will be ignored for this guest common: bad_field: "The following settings shouldn't exist: %{fields}" chef: