Switch config to not implicitly use I18n.

This commit is contained in:
Mitchell Hashimoto 2010-09-21 20:38:19 -06:00
parent b909adde1c
commit 85bbb5dd87
5 changed files with 10 additions and 18 deletions

View File

@ -10,11 +10,9 @@ module Vagrant
@errors = []
end
# Adds an error to the list of errors. The message key must be a key
# to an I18n translatable error message. Opts can be specified as
# interpolation variables for the message.
def add(message_key, opts=nil)
@errors << I18n.t(message_key, opts)
# Adds an error to the list of errors.
def add(message)
@errors << message
end
end
end

View File

@ -18,10 +18,10 @@ module Vagrant
def validate(errors)
[:username, :host, :port, :forwarded_port_key, :max_tries, :timeout, :private_key_path].each do |field|
errors.add("vagrant.config.common.error_empty", :field => field) if !instance_variable_get("@#{field}".to_sym)
errors.add(I18n.t("vagrant.config.common.error_empty", :field => field)) if !instance_variable_get("@#{field}".to_sym)
end
errors.add("vagrant.config.ssh.private_key_missing", :path => private_key_path) if !File.file?(private_key_path)
errors.add(I18n.t("vagrant.config.ssh.private_key_missing", :path => private_key_path)) if !File.file?(private_key_path)
end
end
end

View File

@ -13,7 +13,7 @@ module Vagrant
def validate(errors)
[:dotfile_name, :home, :host].each do |field|
errors.add("vagrant.config.common.error_empty", :field => field) if !instance_variable_get("@#{field}".to_sym)
errors.add(I18n.t("vagrant.config.common.error_empty", :field => field)) if !instance_variable_get("@#{field}".to_sym)
end
end
end

View File

@ -98,13 +98,13 @@ module Vagrant
def validate(errors)
shared_folders.each do |name, options|
if !File.directory?(File.expand_path(options[:hostpath].to_s, env.root_path))
errors.add("vagrant.config.vm.shared_folder_hostpath_missing",
errors.add(I18n.t("vagrant.config.vm.shared_folder_hostpath_missing",
:name => name,
:path => options[:hostpath])
:path => options[:hostpath]))
end
end
errors.add("vagrant.config.vm.boot_mode_invalid") if ![:vrdp, :gui].include?(boot_mode.to_sym)
errors.add(I18n.t("vagrant.config.vm.boot_mode_invalid")) if ![:vrdp, :gui].include?(boot_mode.to_sym)
end
end
end

View File

@ -13,12 +13,6 @@ class ConfigErrorsTest < Test::Unit::TestCase
should "add errors" do
key = "vagrant.test.errors.test_key"
@instance.add(key)
assert_equal I18n.t(key), @instance.errors.first
end
should "interpolate error messages if options given" do
key = "vagrant.test.errors.test_key_with_interpolation"
@instance.add(key, :key => "hey")
assert_equal I18n.t(key, :key => "hey"), @instance.errors.first
assert_equal key, @instance.errors.first
end
end