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 = [] @errors = []
end end
# Adds an error to the list of errors. The message key must be a key # Adds an error to the list of errors.
# to an I18n translatable error message. Opts can be specified as def add(message)
# interpolation variables for the message. @errors << message
def add(message_key, opts=nil)
@errors << I18n.t(message_key, opts)
end end
end end
end end

View File

@ -18,10 +18,10 @@ module Vagrant
def validate(errors) def validate(errors)
[:username, :host, :port, :forwarded_port_key, :max_tries, :timeout, :private_key_path].each do |field| [: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 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 end
end end

View File

@ -13,7 +13,7 @@ module Vagrant
def validate(errors) def validate(errors)
[:dotfile_name, :home, :host].each do |field| [: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 end
end end

View File

@ -98,13 +98,13 @@ module Vagrant
def validate(errors) def validate(errors)
shared_folders.each do |name, options| shared_folders.each do |name, options|
if !File.directory?(File.expand_path(options[:hostpath].to_s, env.root_path)) 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, :name => name,
:path => options[:hostpath]) :path => options[:hostpath]))
end end
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 end
end end

View File

@ -13,12 +13,6 @@ class ConfigErrorsTest < Test::Unit::TestCase
should "add errors" do should "add errors" do
key = "vagrant.test.errors.test_key" key = "vagrant.test.errors.test_key"
@instance.add(key) @instance.add(key)
assert_equal I18n.t(key), @instance.errors.first assert_equal 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
end end
end end