From 85bbb5dd87771b4c8675285da665fb6b7b6ba17c Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 21 Sep 2010 20:38:19 -0600 Subject: [PATCH] Switch config to not implicitly use I18n. --- lib/vagrant/config/error_recorder.rb | 8 +++----- lib/vagrant/config/ssh.rb | 4 ++-- lib/vagrant/config/vagrant.rb | 2 +- lib/vagrant/config/vm.rb | 6 +++--- test/vagrant/config/error_recorder_test.rb | 8 +------- 5 files changed, 10 insertions(+), 18 deletions(-) diff --git a/lib/vagrant/config/error_recorder.rb b/lib/vagrant/config/error_recorder.rb index ae8991e3db7..eda3ee62c4e 100644 --- a/lib/vagrant/config/error_recorder.rb +++ b/lib/vagrant/config/error_recorder.rb @@ -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 diff --git a/lib/vagrant/config/ssh.rb b/lib/vagrant/config/ssh.rb index 1a9a968ea6f..ca15c2cd487 100644 --- a/lib/vagrant/config/ssh.rb +++ b/lib/vagrant/config/ssh.rb @@ -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 diff --git a/lib/vagrant/config/vagrant.rb b/lib/vagrant/config/vagrant.rb index 45cd0e023ce..ee4856e0bd8 100644 --- a/lib/vagrant/config/vagrant.rb +++ b/lib/vagrant/config/vagrant.rb @@ -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 diff --git a/lib/vagrant/config/vm.rb b/lib/vagrant/config/vm.rb index 63e003a9441..6d549d9102c 100644 --- a/lib/vagrant/config/vm.rb +++ b/lib/vagrant/config/vm.rb @@ -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 diff --git a/test/vagrant/config/error_recorder_test.rb b/test/vagrant/config/error_recorder_test.rb index 90be44ce7fc..c9b1d37ace9 100644 --- a/test/vagrant/config/error_recorder_test.rb +++ b/test/vagrant/config/error_recorder_test.rb @@ -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