Skip to content

Commit

Permalink
Switch config to not implicitly use I18n.
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchellh committed Sep 22, 2010
1 parent b909add commit 85bbb5d
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 18 deletions.
8 changes: 3 additions & 5 deletions lib/vagrant/config/error_recorder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@ def initialize
@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
Expand Down
4 changes: 2 additions & 2 deletions lib/vagrant/config/ssh.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ def private_key_path

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
Expand Down
2 changes: 1 addition & 1 deletion lib/vagrant/config/vagrant.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def initialize

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
Expand Down
6 changes: 3 additions & 3 deletions lib/vagrant/config/vm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,13 @@ def define(name, options=nil, &block)
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
Expand Down
8 changes: 1 addition & 7 deletions test/vagrant/config/error_recorder_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 85bbb5d

Please sign in to comment.