From beb84d32127ff0ecb6a393778ba543f6c65ba144 Mon Sep 17 00:00:00 2001 From: Seth Vargo Date: Tue, 24 Nov 2015 15:48:07 -0500 Subject: [PATCH] Move to I18n --- plugins/commands/port/command.rb | 18 ++++++------------ plugins/commands/port/locales/en.yml | 16 ++++++++++++++++ plugins/commands/port/plugin.rb | 12 +++++++++++- .../unit/plugins/commands/port/command_test.rb | 9 +++++++-- 4 files changed, 40 insertions(+), 15 deletions(-) create mode 100644 plugins/commands/port/locales/en.yml diff --git a/plugins/commands/port/command.rb b/plugins/commands/port/command.rb index 2ffca44d9..a62789f6b 100644 --- a/plugins/commands/port/command.rb +++ b/plugins/commands/port/command.rb @@ -36,27 +36,21 @@ module VagrantPlugins # Vagrant::Action::Builtin::CheckRunning) if !vm.provider.capability?(:forwarded_ports) - @env.ui.error <<-EOH.strip -The #{vm.provider_name} provider does not support listing forwarded ports. This -is most likely a limitation of the provider and not a bug in Vagrant. If you -believe this is a bug in Vagrant, please search existing issues before opening -a new one. -EOH + @env.ui.error(I18n.t("port_command.missing_capability", + provider: vm.provider_name, + )) return 1 end ports = vm.provider.capability(:forwarded_ports) if ports.empty? - @env.ui.info("The machine has no configured forwarded ports") + @env.ui.info(I18n.t("port_command.empty_ports")) return 0 end - @env.ui.info <<-EOH -The forwarded ports for the machine are listed below. Please note that these -values may differ from values configured in the Vagrantfile if the provider -supports automatic port collision detection and resolution. -EOH + @env.ui.info(I18n.t("port_command.details")) + @env.ui.info("") ports.each do |guest, host| @env.ui.info("#{guest.to_s.rjust(6)} (guest) => #{host} (host)") @env.ui.machine("forwarded_port", guest, host, target: vm.name.to_s) diff --git a/plugins/commands/port/locales/en.yml b/plugins/commands/port/locales/en.yml new file mode 100644 index 000000000..8bcfdf1c7 --- /dev/null +++ b/plugins/commands/port/locales/en.yml @@ -0,0 +1,16 @@ +en: + port_command: + details: |- + The forwarded ports for the machine are listed below. Please note that + these values may differ from values configured in the Vagrantfile if the + provider supports automatic port collision detection and resolution. + empty_ports: |- + The provider reported there are no forwarded ports for this virtual + machine. This can be caused if there are no ports specified in the + Vagrantfile or if the virtual machine is not currently running. Please + check that the virtual machine is running and try again. + missing_capability: |- + The %{provider} provider does not support listing forwarded ports. This is + most likely a limitation of the provider and not a bug in Vagrant. If you + believe this is a bug in Vagrant, please search existing issues before + opening a new one. diff --git a/plugins/commands/port/plugin.rb b/plugins/commands/port/plugin.rb index be1572afd..7437f0436 100644 --- a/plugins/commands/port/plugin.rb +++ b/plugins/commands/port/plugin.rb @@ -9,9 +9,19 @@ module VagrantPlugins DESC command("port") do - require File.expand_path("../command", __FILE__) + require_relative "command" + self.init! Command end + + protected + + def self.init! + return if defined?(@_init) + I18n.load_path << File.expand_path("../locales/en.yml", __FILE__) + I18n.reload! + @_init = true + end end end end diff --git a/test/unit/plugins/commands/port/command_test.rb b/test/unit/plugins/commands/port/command_test.rb index 7bd3dee4e..5ec4027de 100644 --- a/test/unit/plugins/commands/port/command_test.rb +++ b/test/unit/plugins/commands/port/command_test.rb @@ -22,6 +22,11 @@ describe VagrantPlugins::CommandPort::Command do let(:machine) { env.machine(env.machine_names[0], :dummy) } + before(:all) do + I18n.load_path << Vagrant.source_root.join("plugins/commands/port/locales/en.yml") + I18n.reload! + end + subject { described_class.new(argv, env) } before do @@ -51,7 +56,7 @@ describe VagrantPlugins::CommandPort::Command do it "ensures the vm is running" do allow(state).to receive(:id).and_return(:stopped) expect(env.ui).to receive(:error).with { |message, _| - expect(message).to include("make this a better error") + expect(message).to include("does not support listing forwarded ports") } expect(subject.execute).to eq(1) @@ -72,7 +77,7 @@ describe VagrantPlugins::CommandPort::Command do .and_return([]) expect(env.ui).to receive(:info).with { |message, _| - expect(message).to include("has no configured forwarded ports") + expect(message).to include("there are no forwarded ports") } expect(subject.execute).to eq(0)