From 8d6d869a626b2776706b09f3f79286d789788c70 Mon Sep 17 00:00:00 2001 From: Maggie Dreyer Date: Wed, 21 Dec 2016 14:48:11 -0800 Subject: [PATCH] (PUP-7042) Mark strings in type This commit marks user-facing error and info strings in `lib/puppet/type/*` for translation. --- lib/puppet/type/augeas.rb | 4 +- lib/puppet/type/cron.rb | 8 ++-- lib/puppet/type/exec.rb | 32 ++++++++-------- lib/puppet/type/file.rb | 41 ++++++++++---------- lib/puppet/type/filebucket.rb | 6 +-- lib/puppet/type/group.rb | 4 +- lib/puppet/type/host.rb | 12 +++--- lib/puppet/type/interface.rb | 2 +- lib/puppet/type/k5login.rb | 2 +- lib/puppet/type/macauthorization.rb | 2 +- lib/puppet/type/mailalias.rb | 4 +- lib/puppet/type/maillist.rb | 2 +- lib/puppet/type/mount.rb | 16 ++++---- lib/puppet/type/package.rb | 8 ++-- lib/puppet/type/resources.rb | 12 +++--- lib/puppet/type/schedule.rb | 18 ++++----- lib/puppet/type/scheduled_task.rb | 4 +- lib/puppet/type/service.rb | 2 +- lib/puppet/type/ssh_authorized_key.rb | 6 +-- lib/puppet/type/sshkey.rb | 8 ++-- lib/puppet/type/tidy.rb | 20 +++++----- lib/puppet/type/user.rb | 54 +++++++++++++-------------- lib/puppet/type/yumrepo.rb | 16 ++++---- lib/puppet/type/zone.rb | 14 +++---- 24 files changed, 149 insertions(+), 148 deletions(-) diff --git a/lib/puppet/type/augeas.rb b/lib/puppet/type/augeas.rb index f73c59caa19..49f8c41531d 100644 --- a/lib/puppet/type/augeas.rb +++ b/lib/puppet/type/augeas.rb @@ -164,7 +164,7 @@ validate do has_lens = !self[:lens].nil? has_incl = !self[:incl].nil? - self.fail "You must specify both the lens and incl parameters, or neither." if has_lens != has_incl + self.fail _("You must specify both the lens and incl parameters, or neither.") if has_lens != has_incl end newparam(:show_diff, :boolean => true, :parent => Puppet::Parameter::Boolean) do @@ -188,7 +188,7 @@ # Make output a bit prettier def change_to_s(currentvalue, newvalue) - "executed successfully" + _("executed successfully") end # if the onlyif resource is provided, then the value is parsed. diff --git a/lib/puppet/type/cron.rb b/lib/puppet/type/cron.rb index 6a062230ddb..de330640556 100644 --- a/lib/puppet/type/cron.rb +++ b/lib/puppet/type/cron.rb @@ -195,7 +195,7 @@ def should=(ary) if retval return retval.to_s else - self.fail "#{value} is not a valid #{self.class.name}" + self.fail _("#{value} is not a valid #{self.class.name}") end end end @@ -253,7 +253,7 @@ def specials end validate do |value| - raise ArgumentError, "Invalid special schedule #{value.inspect}" unless specials.include?(value) + raise ArgumentError, _("Invalid special schedule #{value.inspect}") unless specials.include?(value) end def munge(value) @@ -326,7 +326,7 @@ def alpha validate do |value| unless value =~ /^\s*(\w+)\s*=\s*(.*)\s*$/ or value == :absent or value == "absent" - raise ArgumentError, "Invalid environment setting #{value.inspect}" + raise ArgumentError, _("Invalid environment setting #{value.inspect}") end end @@ -433,7 +433,7 @@ def should_to_s(newvalue = @should) [ :minute, :hour, :weekday, :monthday, :month ].each do |field| next unless self[field] next if self[field] == :absent - raise ArgumentError, "#{self.ref} cannot specify both a special schedule and a value for #{field}" + raise ArgumentError, _("#{self.ref} cannot specify both a special schedule and a value for #{field}") end end diff --git a/lib/puppet/type/exec.rb b/lib/puppet/type/exec.rb index 8ccd9900762..63d61329452 100644 --- a/lib/puppet/type/exec.rb +++ b/lib/puppet/type/exec.rb @@ -101,7 +101,7 @@ def event_name # Make output a bit prettier def change_to_s(currentvalue, newvalue) - "executed successfully" + _("executed successfully") end # First verify that all of our checks pass. @@ -135,7 +135,7 @@ def sync end end rescue Timeout::Error - self.fail Puppet::Error, "Command exceeded timeout", $! + self.fail Puppet::Error, _("Command exceeded timeout"), $! end if log = @resource[:logoutput] @@ -159,9 +159,9 @@ def sync unless self.should.include?(@status.exitstatus.to_s) if @resource.parameter(:command).sensitive # Don't print sensitive commands in the clear - self.fail("[command redacted] returned #{@status.exitstatus} instead of one of [#{self.should.join(",")}]") + self.fail(_("[command redacted] returned #{@status.exitstatus} instead of one of [#{self.should.join(",")}]")) else - self.fail("'#{self.resource[:command]}' returned #{@status.exitstatus} instead of one of [#{self.should.join(",")}]") + self.fail(_("'#{self.resource[:command]}' returned #{@status.exitstatus} instead of one of [#{self.should.join(",")}]")) end end @@ -179,7 +179,7 @@ def sync any output is logged at the `err` log level." validate do |command| - raise ArgumentError, "Command must be a String, got value of class #{command.class}" unless command.is_a? String + raise ArgumentError, _("Command must be a String, got value of class #{command.class}") unless command.is_a? String end end @@ -208,9 +208,9 @@ def value=(*values) validate do |user| if Puppet.features.microsoft_windows? - self.fail "Unable to execute commands as other users on Windows" + self.fail _("Unable to execute commands as other users on Windows") elsif !Puppet.features.root? && resource.current_username() != user - self.fail "Only root can execute commands as other users" + self.fail _("Only root can execute commands as other users") end end end @@ -261,7 +261,7 @@ def value=(*values) values = [values] unless values.is_a? Array values.each do |value| unless value =~ /\w+=/ - raise ArgumentError, "Invalid environment setting '#{value}'" + raise ArgumentError, _("Invalid environment setting '#{value}'") end end end @@ -274,7 +274,7 @@ def value=(*values) if value =~ /^0?[0-7]{1,4}$/ return value.to_i(8) else - raise Puppet::Error, "The umask specification is invalid: #{value.inspect}" + raise Puppet::Error, _("The umask specification is invalid: #{value.inspect}") end end end @@ -290,7 +290,7 @@ def value=(*values) begin value = Float(value) rescue ArgumentError - raise ArgumentError, "The timeout must be a number.", $!.backtrace + raise ArgumentError, _("The timeout must be a number."), $!.backtrace end [value, 0.0].max end @@ -308,11 +308,11 @@ def value=(*values) munge do |value| if value.is_a?(String) unless value =~ /^[\d]+$/ - raise ArgumentError, "Tries must be an integer" + raise ArgumentError, _("Tries must be an integer") end value = Integer(value) end - raise ArgumentError, "Tries must be an integer >= 1" if value < 1 + raise ArgumentError, _("Tries must be an integer >= 1") if value < 1 value end @@ -325,11 +325,11 @@ def value=(*values) munge do |value| if value.is_a?(String) unless value =~ /^[-\d.]+$/ - raise ArgumentError, "try_sleep must be a number" + raise ArgumentError, _("try_sleep must be a number") end value = Float(value) end - raise ArgumentError, "try_sleep cannot be a negative number" if value < 0 + raise ArgumentError, _("try_sleep cannot be a negative number") if value < 0 value end @@ -443,7 +443,7 @@ def check(value) begin output, status = provider.run(value, true) rescue Timeout::Error - err "Check #{value.inspect} exceeded timeout" + err _("Check #{value.inspect} exceeded timeout") return false end @@ -494,7 +494,7 @@ def check(value) begin output, status = provider.run(value, true) rescue Timeout::Error - err "Check #{value.inspect} exceeded timeout" + err _("Check #{value.inspect} exceeded timeout") return false end diff --git a/lib/puppet/type/file.rb b/lib/puppet/type/file.rb index 5f89b90d1ad..4aa4dbbfcb6 100644 --- a/lib/puppet/type/file.rb +++ b/lib/puppet/type/file.rb @@ -53,7 +53,7 @@ def self.title_patterns validate do |value| unless Puppet::Util.absolute_path?(value) - fail Puppet::Error, "File paths must be fully qualified, not '#{value}'" + fail Puppet::Error, _("File paths must be fully qualified, not '#{value}'") end end @@ -121,7 +121,7 @@ def self.title_patterns when String value else - self.fail "Invalid backup type #{value.inspect}" + self.fail _("Invalid backup type #{value.inspect}") end end end @@ -165,7 +165,7 @@ def self.title_patterns when :false; false when :remote; :remote else - self.fail "Invalid recurse value #{value.inspect}" + self.fail _("Invalid recurse value #{value.inspect}") end end end @@ -198,7 +198,7 @@ def self.title_patterns when Integer; value when /^\d+$/; Integer(value) else - self.fail "Invalid recurselimit value #{value.inspect}" + self.fail _("Invalid recurselimit value #{value.inspect}") end end end @@ -368,17 +368,17 @@ def self.title_patterns end creator_count += 1 if @parameters.include?(:source) - self.fail "You cannot specify more than one of #{CREATORS.collect { |p| p.to_s}.join(", ")}" if creator_count > 1 + self.fail _("You cannot specify more than one of #{CREATORS.collect { |p| p.to_s}.join(", ")}") if creator_count > 1 - self.fail "You cannot specify a remote recursion without a source" if !self[:source] && self[:recurse] == :remote + self.fail _("You cannot specify a remote recursion without a source") if !self[:source] && self[:recurse] == :remote - self.fail "You cannot specify source when using checksum 'none'" if self[:checksum] == :none && !self[:source].nil? + self.fail _("You cannot specify source when using checksum 'none'") if self[:checksum] == :none && !self[:source].nil? SOURCE_ONLY_CHECKSUMS.each do |checksum_type| - self.fail "You cannot specify content when using checksum '#{checksum_type}'" if self[:checksum] == checksum_type && !self[:content].nil? + self.fail _("You cannot specify content when using checksum '#{checksum_type}'") if self[:checksum] == checksum_type && !self[:content].nil? end - self.warning "Possible error: recurselimit is set but not recurse, no recursion will happen" if !self[:recurse] && self[:recurselimit] + self.warning _("Possible error: recurselimit is set but not recurse, no recursion will happen") if !self[:recurse] && self[:recurselimit] if @parameters[:content] && @parameters[:content].actual_content # Now that we know the checksum, update content (in case it was created before checksum was known). @@ -386,10 +386,10 @@ def self.title_patterns end if self[:checksum] && self[:checksum_value] && !send("#{self[:checksum]}?", self[:checksum_value]) - self.fail "Checksum value '#{self[:checksum_value]}' is not a valid checksum type #{self[:checksum]}" + self.fail _("Checksum value '#{self[:checksum_value]}' is not a valid checksum type #{self[:checksum]}") end - self.warning "Checksum value is ignored unless content or source are specified" if self[:checksum_value] && !self[:content] && !self[:source] + self.warning _("Checksum value is ignored unless content or source are specified") if self[:checksum_value] && !self[:content] && !self[:source] provider.validate if provider.respond_to?(:validate) end @@ -427,11 +427,11 @@ def bucket return nil if backup =~ /^\./ unless catalog or backup == "puppet" - fail "Can not find filebucket for backups without a catalog" + fail _("Can not find filebucket for backups without a catalog") end unless catalog and filebucket = catalog.resource(:filebucket, backup) or backup == "puppet" - fail "Could not find filebucket #{backup} specified in backup" + fail _("Could not find filebucket #{backup} specified in backup") end return default_bucket unless filebucket @@ -737,7 +737,7 @@ def remove_existing(should) when "link", "file" return remove_file(current_type, wanted_type) else - self.fail "Could not back up files of type #{current_type}" + self.fail _("Could not back up files of type #{current_type}") end end @@ -747,9 +747,7 @@ def retrieve # catalog validation (because that would be a breaking change from Puppet 4). if Puppet.features.microsoft_windows? && parameter(:source) && [:use, :use_when_creating].include?(self[:source_permissions]) - err_msg = "Copying owner/mode/group from the source file on Windows" << - " is not supported; use source_permissions => ignore." - + err_msg = _("Copying owner/mode/group from the source file on Windows is not supported; use source_permissions => ignore.") if self[:owner] == nil || self[:group] == nil || self[:mode] == nil # Fail on Windows if source permissions are being used and the file resource # does not have mode owner, group, and mode all set (which would take precedence). @@ -830,7 +828,7 @@ def stat rescue Errno::ENOTDIR => error nil rescue Errno::EACCES => error - warning "Could not stat; permission denied" + warning _("Could not stat; permission denied") nil end end @@ -952,7 +950,7 @@ def remove_directory(wanted_type) stat_needed true else - notice "Not removing directory; use 'force' to override" + notice _("Not removing directory; use 'force' to override") false end end @@ -976,7 +974,8 @@ def stat_needed # @return [void] def backup_existing unless perform_backup - raise Puppet::Error, "Could not back up; will not replace" + #TRANSLATORS refers to a file which could not be backed up + raise Puppet::Error, _("Could not back up; will not replace") end end @@ -990,7 +989,7 @@ def fail_if_checksum_is_wrong(path, content_checksum) newsum = parameter(:checksum).sum_file(path) return if [:absent, nil, content_checksum].include?(newsum) - self.fail "File written to disk did not match checksum; discarding changes (#{content_checksum} vs #{newsum})" + self.fail _("File written to disk did not match checksum; discarding changes (#{content_checksum} vs #{newsum})") end def write_temporary_file? diff --git a/lib/puppet/type/filebucket.rb b/lib/puppet/type/filebucket.rb index 04c28d8ebe1..fb3966c8669 100644 --- a/lib/puppet/type/filebucket.rb +++ b/lib/puppet/type/filebucket.rb @@ -71,11 +71,11 @@ module Puppet validate do |value| if value.is_a? Array - raise ArgumentError, "You can only have one filebucket path" + raise ArgumentError, _("You can only have one filebucket path") end if value.is_a? String and not Puppet::Util.absolute_path?(value) - raise ArgumentError, "Filebucket paths must be absolute" + raise ArgumentError, _("Filebucket paths must be absolute") end true @@ -111,7 +111,7 @@ def mkbucket begin @bucket = Puppet::FileBucket::Dipper.new(args) rescue => detail - message = "Could not create #{type} filebucket: #{detail}" + message = _("Could not create #{type} filebucket: #{detail}") self.log_exception(detail, message) self.fail(message) end diff --git a/lib/puppet/type/group.rb b/lib/puppet/type/group.rb index 517c627f353..6b60d70ed11 100644 --- a/lib/puppet/type/group.rb +++ b/lib/puppet/type/group.rb @@ -66,7 +66,7 @@ def sync if gid =~ /^[-0-9]+$/ gid = Integer(gid) else - self.fail "Invalid GID #{gid}" + self.fail _("Invalid GID #{gid}") end when Symbol unless gid == :absent @@ -157,7 +157,7 @@ def delimiter end validate do |value| - raise ArgumentError, "Attributes value pairs must be separated by an =" unless value.include?("=") + raise ArgumentError, _("Attributes value pairs must be separated by an =") unless value.include?("=") end end diff --git a/lib/puppet/type/host.rb b/lib/puppet/type/host.rb index c9273ad10f5..1f145638fae 100644 --- a/lib/puppet/type/host.rb +++ b/lib/puppet/type/host.rb @@ -29,7 +29,7 @@ def valid_newline?(addr) validate do |value| return true if ((valid_v4?(value) || valid_v6?(value)) && (valid_newline?(value))) - raise Puppet::Error, "Invalid IP address #{value.inspect}" + raise Puppet::Error, _("Invalid IP address #{value.inspect}") end end @@ -48,8 +48,8 @@ def inclusive? validate do |value| # This regex already includes newline check. - raise Puppet::Error, "Host aliases cannot include whitespace" if value =~ /\s/ - raise Puppet::Error, "Host aliases cannot be an empty string. Use an empty array to delete all host_aliases " if value =~ /^\s*$/ + raise Puppet::Error, _("Host aliases cannot include whitespace") if value =~ /\s/ + raise Puppet::Error, _("Host aliases cannot be an empty string. Use an empty array to delete all host_aliases ") if value =~ /^\s*$/ end end @@ -57,7 +57,7 @@ def inclusive? newproperty(:comment) do desc "A comment that will be attached to the line with a # character." validate do |value| - raise Puppet::Error, "Comment cannot include newline" if (value =~ /\n/ || value =~ /\r/) + raise Puppet::Error, _("Comment cannot include newline") if (value =~ /\n/ || value =~ /\r/) end end @@ -81,10 +81,10 @@ def inclusive? validate do |value| value.split('.').each do |hostpart| unless hostpart =~ /^([\d\w]+|[\d\w][\d\w\-]+[\d\w])$/ - raise Puppet::Error, "Invalid host name" + raise Puppet::Error, _("Invalid host name") end end - raise Puppet::Error, "Hostname cannot include newline" if (value =~ /\n/ || value =~ /\r/) + raise Puppet::Error, _("Hostname cannot include newline") if (value =~ /\n/ || value =~ /\r/) end end diff --git a/lib/puppet/type/interface.rb b/lib/puppet/type/interface.rb index a0ca364f8fb..85c9ba021f6 100644 --- a/lib/puppet/type/interface.rb +++ b/lib/puppet/type/interface.rb @@ -94,7 +94,7 @@ validate do |values| values = [values] unless values.is_a?(Array) values.each do |value| - self.fail "Invalid interface ip address" unless parse(value.gsub(/\s*(eui-64|link-local)\s*$/,'')) + self.fail _("Invalid interface ip address") unless parse(value.gsub(/\s*(eui-64|link-local)\s*$/,'')) end end diff --git a/lib/puppet/type/k5login.rb b/lib/puppet/type/k5login.rb index bc96d5b37f8..2f689a9310e 100644 --- a/lib/puppet/type/k5login.rb +++ b/lib/puppet/type/k5login.rb @@ -20,7 +20,7 @@ validate do |value| unless absolute_path?(value) - raise Puppet::Error, "File paths must be fully qualified." + raise Puppet::Error, _("File paths must be fully qualified.") end end end diff --git a/lib/puppet/type/macauthorization.rb b/lib/puppet/type/macauthorization.rb index 5985a2e6219..2d2eaf73070 100644 --- a/lib/puppet/type/macauthorization.rb +++ b/lib/puppet/type/macauthorization.rb @@ -31,7 +31,7 @@ def munge_boolean(value) def munge_integer(value) Integer(value) rescue ArgumentError - fail("munge_integer only takes integers") + fail "munge_integer only takes integers") end newparam(:name) do diff --git a/lib/puppet/type/mailalias.rb b/lib/puppet/type/mailalias.rb index 624f293a7b0..3492a2e75d7 100644 --- a/lib/puppet/type/mailalias.rb +++ b/lib/puppet/type/mailalias.rb @@ -36,7 +36,7 @@ def should_to_s(value) validate do |value| unless Puppet::Util.absolute_path?(value) - fail Puppet::Error, "File paths must be fully qualified, not '#{value}'" + fail Puppet::Error, _("File paths must be fully qualified, not '#{value}'") end end end @@ -55,7 +55,7 @@ def should_to_s(value) validate do if self[:recipient] && self[:file] - self.fail "You cannot specify both a recipient and a file" + self.fail _("You cannot specify both a recipient and a file") end end end diff --git a/lib/puppet/type/maillist.rb b/lib/puppet/type/maillist.rb index dfe5e22d525..452869868a5 100644 --- a/lib/puppet/type/maillist.rb +++ b/lib/puppet/type/maillist.rb @@ -11,7 +11,7 @@ module Puppet end def change_to_s(current_value, newvalue) - return "Purged #{resource}" if newvalue == :purged + return _("Purged #{resource}") if newvalue == :purged super end diff --git a/lib/puppet/type/mount.rb b/lib/puppet/type/mount.rb index 6e09f687347..b400a9c8b99 100644 --- a/lib/puppet/type/mount.rb +++ b/lib/puppet/type/mount.rb @@ -65,7 +65,7 @@ module Puppet # the wrong attributes so I sync AFTER the umount return :mount_unmounted else - raise Puppet::Error, "Unexpected change from #{current_value} to unmounted}" + raise Puppet::Error, _("Unexpected change from #{current_value} to unmounted}") end end @@ -131,7 +131,7 @@ def syncothers path, depending on the operating system." validate do |value| - raise Puppet::Error, "device must not contain whitespace: #{value}" if value =~ /\s/ + raise Puppet::Error, _("device must not contain whitespace: #{value}") if value =~ /\s/ end end @@ -157,7 +157,7 @@ def syncothers end validate do |value| - raise Puppet::Error, "blockdevice must not contain whitespace: #{value}" if value =~ /\s/ + raise Puppet::Error, _("blockdevice must not contain whitespace: #{value}") if value =~ /\s/ end end @@ -166,8 +166,8 @@ def syncothers operating system. This is a required option." validate do |value| - raise Puppet::Error, "fstype must not contain whitespace: #{value}" if value =~ /\s/ - raise Puppet::Error, "fstype must not be an empty string" if value.empty? + raise Puppet::Error, _("fstype must not contain whitespace: #{value}") if value =~ /\s/ + raise Puppet::Error, _("fstype must not be an empty string") if value.empty? end end @@ -177,8 +177,8 @@ def syncothers Consult the fstab(5) man page for system-specific details." validate do |value| - raise Puppet::Error, "options must not contain whitespace: #{value}" if value =~ /\s/ - raise Puppet::Error, "options must not be an empty string" if value.empty? + raise Puppet::Error, _("options must not contain whitespace: #{value}") if value =~ /\s/ + raise Puppet::Error, _("options must not be an empty string") if value.empty? end end @@ -243,7 +243,7 @@ def munge(value) isnamevar validate do |value| - raise Puppet::Error, "name must not contain whitespace: #{value}" if value =~ /\s/ + raise Puppet::Error, _("name must not contain whitespace: #{value}") if value =~ /\s/ end munge do |value| diff --git a/lib/puppet/type/package.rb b/lib/puppet/type/package.rb index a3d66ea56aa..64003ec9b65 100644 --- a/lib/puppet/type/package.rb +++ b/lib/puppet/type/package.rb @@ -111,7 +111,7 @@ module Puppet begin provider.update rescue => detail - self.fail Puppet::Error, "Could not update: #{detail}", detail + self.fail Puppet::Error, _("Could not update: #{detail}"), detail end if current == :absent @@ -125,7 +125,7 @@ module Puppet begin provider.install rescue => detail - self.fail Puppet::Error, "Could not update: #{detail}", detail + self.fail Puppet::Error, _("Could not update: #{detail}"), detail end if self.retrieve == :absent @@ -160,7 +160,7 @@ def insync?(is) @latest = provider.latest @lateststamp = Time.now.to_i rescue => detail - error = Puppet::Error.new("Could not get latest version: #{detail}") + error = Puppet::Error.new(_("Could not get latest version: #{detail}")) error.set_backtrace(detail.backtrace) raise error end @@ -260,7 +260,7 @@ def change_to_s(currentvalue, newvalue) validate do |value| if !value.is_a?(String) - raise ArgumentError, "Name must be a String not #{value.class}" + raise ArgumentError, _("Name must be a String not #{value.class}") end end end diff --git a/lib/puppet/type/resources.rb b/lib/puppet/type/resources.rb index 7eb5fb7ca12..6b70a9a4d6c 100644 --- a/lib/puppet/type/resources.rb +++ b/lib/puppet/type/resources.rb @@ -12,7 +12,7 @@ desc "The name of the type to be managed." validate do |name| - raise ArgumentError, "Could not find resource type '#{name}'" unless Puppet::Type.type(name) + raise ArgumentError, _("Could not find resource type '#{name}'") unless Puppet::Type.type(name) end munge { |v| v.to_s } @@ -30,9 +30,9 @@ validate do |value| if munge(value) unless @resource.resource_type.respond_to?(:instances) - raise ArgumentError, "Purging resources of type #{@resource[:name]} is not supported, since they cannot be queried from the system" + raise ArgumentError, _("Purging resources of type #{@resource[:name]} is not supported, since they cannot be queried from the system") end - raise ArgumentError, "Purging is only supported on types that accept 'ensure'" unless @resource.resource_type.validproperty?(:ensure) + raise ArgumentError, _("Purging is only supported on types that accept 'ensure'") unless @resource.resource_type.validproperty?(:ensure) end end end @@ -54,7 +54,7 @@ false when Integer; value else - raise ArgumentError, "Invalid value #{value.inspect}" + raise ArgumentError, _("Invalid value #{value.inspect}") end end @@ -81,7 +81,7 @@ when String Integer(v) else - raise ArgumentError, "Invalid value #{v.inspect}." + raise ArgumentError, _("Invalid value #{v.inspect}.") end end end @@ -100,7 +100,7 @@ def check(resource) def able_to_ensure_absent?(resource) resource[:ensure] = :absent rescue ArgumentError, Puppet::Error - err "The 'ensure' attribute on #{self[:name]} resources does not accept 'absent' as a value" + err _("The 'ensure' attribute on #{self[:name]} resources does not accept 'absent' as a value") false end diff --git a/lib/puppet/type/schedule.rb b/lib/puppet/type/schedule.rb index 65d898ea95a..b32eddc691c 100644 --- a/lib/puppet/type/schedule.rb +++ b/lib/puppet/type/schedule.rb @@ -93,7 +93,7 @@ module Puppet values.each { |value| unless value.is_a?(String) and value =~ /\d+(:\d+){0,2}\s*-\s*\d+(:\d+){0,2}/ - self.fail "Invalid range value '#{value}'" + self.fail _("Invalid range value '#{value}'") end } end @@ -110,15 +110,15 @@ module Puppet range << val.split(":").collect { |n| n.to_i } } - self.fail "Invalid range #{value}" if range.length != 2 + self.fail _("Invalid range #{value}") if range.length != 2 # Make sure the hours are valid [range[0][0], range[1][0]].each do |n| - raise ArgumentError, "Invalid hour '#{n}'" if n < 0 or n > 23 + raise ArgumentError, _("Invalid hour '#{n}'") if n < 0 or n > 23 end [range[0][1], range[1][1]].each do |n| - raise ArgumentError, "Invalid minute '#{n}'" if n and (n < 0 or n > 59) + raise ArgumentError, _("Invalid minute '#{n}'") if n and (n < 0 or n > 59) end ret << range } @@ -152,7 +152,7 @@ def match?(previous, now) unless time.hour == range[0] self.devfail( - "Incorrectly converted time: #{time}: #{time.hour} vs #{range[0]}" + _("Incorrectly converted time: #{time}: #{time.hour} vs #{range[0]}") ) end @@ -161,7 +161,7 @@ def match?(previous, now) unless limits[0] < limits[1] self.info( - "Assuming upper limit should be that time the next day" + _("Assuming upper limit should be that time the next day") ) # Find midnight between the two days. Adding one second @@ -319,7 +319,7 @@ def match?(previous, now) validate do |value| unless value.is_a?(Integer) or value =~ /^\d+$/ raise Puppet::Error, - "Repeat must be a number" + _("Repeat must be a number") end # This implicitly assumes that 'periodmatch' is distance -- that @@ -328,7 +328,7 @@ def match?(previous, now) if value != 1 and @resource[:periodmatch] != :distance raise Puppet::Error, - "Repeat must be 1 unless periodmatch is 'distance', not '#{@resource[:periodmatch]}'" + _("Repeat must be 1 unless periodmatch is 'distance', not '#{@resource[:periodmatch]}'") end end @@ -371,7 +371,7 @@ def match?(previous, now) values.each { |value| unless value.is_a?(String) and (value =~ /^[0-6]$/ or value =~ /^(Mon|Tues?|Wed(?:nes)?|Thu(?:rs)?|Fri|Sat(?:ur)?|Sun)(day)?$/i) - raise ArgumentError, "%s is not a valid day of the week" % value + raise ArgumentError, _("%s is not a valid day of the week") % value end } end diff --git a/lib/puppet/type/scheduled_task.rb b/lib/puppet/type/scheduled_task.rb index 0a684fb61e6..14b78551c71 100644 --- a/lib/puppet/type/scheduled_task.rb +++ b/lib/puppet/type/scheduled_task.rb @@ -31,7 +31,7 @@ desc "The full path to the application to run, without any arguments." validate do |value| - raise Puppet::Error.new('Must be specified using an absolute path.') unless absolute_path?(value) + raise Puppet::Error.new(_('Must be specified using an absolute path.')) unless absolute_path?(value) end munge do |value| # windows converts slashes to backslashes, so the *is* value @@ -45,7 +45,7 @@ desc "The full path of the directory in which to start the command." validate do |value| - raise Puppet::Error.new('Must be specified using an absolute path.') unless absolute_path?(value) + raise Puppet::Error.new(_('Must be specified using an absolute path.')) unless absolute_path?(value) end end diff --git a/lib/puppet/type/service.rb b/lib/puppet/type/service.rb index 1f8d26687c1..31217eec42a 100644 --- a/lib/puppet/type/service.rb +++ b/lib/puppet/type/service.rb @@ -86,7 +86,7 @@ def insync?(current) validate do |value| if value == :manual and !Puppet.features.microsoft_windows? - raise Puppet::Error.new("Setting enable to manual is only supported on Microsoft Windows.") + raise Puppet::Error.new(_("Setting enable to manual is only supported on Microsoft Windows.")) end end end diff --git a/lib/puppet/type/ssh_authorized_key.rb b/lib/puppet/type/ssh_authorized_key.rb index a0f94d708b6..cc6375f2fbe 100644 --- a/lib/puppet/type/ssh_authorized_key.rb +++ b/lib/puppet/type/ssh_authorized_key.rb @@ -71,7 +71,7 @@ module Puppet the `name` attribute/resource title." validate do |value| - raise Puppet::Error, "Key must not contain whitespace: #{value}" if value =~ /\s/ + raise Puppet::Error, _("Key must not contain whitespace: #{value}") if value =~ /\s/ end end @@ -130,7 +130,7 @@ def should_to_s(value) validate do |value| unless value == :absent or value =~ /^[-a-z0-9A-Z_]+(?:=\".*?\")?$/ - raise Puppet::Error, "Option #{value} is not valid. A single option must either be of the form 'option' or 'option=\"value\". Multiple options must be provided as an array" + raise Puppet::Error, _("Option #{value} is not valid. A single option must either be of the form 'option' or 'option=\"value\". Multiple options must be provided as an array") end end end @@ -147,7 +147,7 @@ def should_to_s(value) return if @parameters.include?(:user) # If neither target nor user is defined, this is an error - raise Puppet::Error, "Attribute 'user' or 'target' is mandatory" + raise Puppet::Error, _("Attribute 'user' or 'target' is mandatory") end # regular expression suitable for use by a ParsedFile based provider diff --git a/lib/puppet/type/sshkey.rb b/lib/puppet/type/sshkey.rb index 8fbbd609c42..610a1697f85 100644 --- a/lib/puppet/type/sshkey.rb +++ b/lib/puppet/type/sshkey.rb @@ -41,10 +41,10 @@ def should validate do |value| if value =~ /\s/ - raise Puppet::Error, "Aliases cannot include whitespace" + raise Puppet::Error, _("Aliases cannot include whitespace") end if value =~ /,/ - raise Puppet::Error, "Aliases must be provided as an array, not a comma-separated list" + raise Puppet::Error, _("Aliases must be provided as an array, not a comma-separated list") end end end @@ -55,8 +55,8 @@ def should isnamevar validate do |value| - raise Puppet::Error, "Resourcename cannot include whitespaces" if value =~ /\s/ - raise Puppet::Error, "No comma in resourcename allowed. If you want to specify aliases use the host_aliases property" if value.include?(',') + raise Puppet::Error, _("Resourcename cannot include whitespaces") if value =~ /\s/ + raise Puppet::Error, _("No comma in resourcename allowed. If you want to specify aliases use the host_aliases property") if value.include?(',') end end diff --git a/lib/puppet/type/tidy.rb b/lib/puppet/type/tidy.rb index 0f4dfa99c89..75791796b43 100644 --- a/lib/puppet/type/tidy.rb +++ b/lib/puppet/type/tidy.rb @@ -45,7 +45,7 @@ when Integer; value when /^\d+$/; Integer(value) else - raise ArgumentError, "Invalid recurse value #{value.inspect}" + raise ArgumentError, _("Invalid recurse value #{value.inspect}") end end end @@ -82,7 +82,7 @@ # Make sure we convert to an array. munge do |value| - fail "Tidy can't use matches with recurse 0, false, or undef" if "#{@resource[:recurse]}" =~ /^(0|false|)$/ + fail _("Tidy can't use matches with recurse 0, false, or undef") if "#{@resource[:recurse]}" =~ /^(0|false|)$/ [value].flatten end @@ -121,7 +121,7 @@ def convert(unit, multi) if num = AgeConvertors[unit] return num * multi else - self.fail "Invalid age unit '#{unit}'" + self.fail _("Invalid age unit '#{unit}'") end end @@ -140,7 +140,8 @@ def tidy?(path, stat) multi = Integer($1) unit = :d else - self.fail "Invalid tidy age #{age}" + #TRANSLATORS tidy is the name of a program and should not be translated + self.fail _("Invalid tidy age #{age}") end convert(unit, multi) @@ -161,7 +162,7 @@ def convert(unit, multi) num.times do result *= 1024 end return result else - self.fail "Invalid size unit '#{unit}'" + self.fail _("Invalid size unit '#{unit}'") end end @@ -178,7 +179,8 @@ def tidy?(path, stat) multi = Integer($1) unit = :k else - self.fail "Invalid tidy size #{age}" + #TRANSLATORS tidy is the name of a program and should not be translated + self.fail _("Invalid tidy size #{age}") end convert(unit, multi) @@ -258,7 +260,7 @@ def generate end found_files = files.find_all { |path| tidy?(path) }.collect { |path| mkfile(path) } result = found_files.each { |file| debug "Tidying #{file.ref}" }.sort { |a,b| b[:path] <=> a[:path] } - notice "Tidying #{found_files.size} files" + notice _("Tidying #{found_files.size} files") # No need to worry about relationships if we don't have rmdirs; there won't be # any directories. @@ -322,10 +324,10 @@ def stat(path) begin Puppet::FileSystem.lstat(path) rescue Errno::ENOENT => error - info "File does not exist" + info _("File does not exist") return nil rescue Errno::EACCES => error - warning "Could not stat; permission denied" + warning _("Could not stat; permission denied") return nil end end diff --git a/lib/puppet/type/user.rb b/lib/puppet/type/user.rb index 512e873d56e..f5a1bea4a8b 100644 --- a/lib/puppet/type/user.rb +++ b/lib/puppet/type/user.rb @@ -163,7 +163,7 @@ def sync end end - fail "Could not find group(s) #{@should.join(",")}" unless found + fail _("Could not find group(s) #{@should.join(",")}") unless found # Use the default event. end @@ -221,22 +221,22 @@ def change_to_s(currentvalue, newvalue) accidental variable interpolation.} validate do |value| - raise ArgumentError, "Passwords cannot include ':'" if value.is_a?(String) and value.include?(":") + raise ArgumentError, _("Passwords cannot include ':'") if value.is_a?(String) and value.include?(":") end def change_to_s(currentvalue, newvalue) if currentvalue == :absent - return "created password" + return _("created password") else - return "changed password" + return _("changed password") end end def is_to_s( currentvalue ) - return '[old password hash redacted]' + return _('[old password hash redacted]') end def should_to_s( newvalue ) - return '[new password hash redacted]' + return _('[new password hash redacted]') end end @@ -255,7 +255,7 @@ def should_to_s( newvalue ) validate do |value| if value.to_s !~ /^-?\d+$/ - raise ArgumentError, "Password minimum age must be provided as a number." + raise ArgumentError, _("Password minimum age must be provided as a number.") end end end @@ -274,7 +274,7 @@ def should_to_s( newvalue ) validate do |value| if value.to_s !~ /^-?\d+$/ - raise ArgumentError, "Password maximum age must be provided as a number." + raise ArgumentError, _("Password maximum age must be provided as a number.") end end end @@ -286,10 +286,10 @@ def should_to_s( newvalue ) validate do |value| if value =~ /^\d+$/ - raise ArgumentError, "Group names must be provided, not GID numbers." + raise ArgumentError, _("Group names must be provided, not GID numbers.") end - raise ArgumentError, "Group names must be provided as an array, not a comma-separated list." if value.include?(",") - raise ArgumentError, "Group names must not be empty. If you want to specify \"no groups\" pass an empty array" if value.empty? + raise ArgumentError, _("Group names must be provided as an array, not a comma-separated list.") if value.include?(",") + raise ArgumentError, _("Group names must not be empty. If you want to specify \"no groups\" pass an empty array") if value.empty? end def change_to_s(currentvalue, newvalue) @@ -375,7 +375,7 @@ def insync?(current) validate do |val| if munge(val) - raise ArgumentError, "User provider #{provider.class.name} can not manage home directories" if provider and not provider.class.manages_homedir? + raise ArgumentError, _("User provider #{provider.class.name} can not manage home directories") if provider and not provider.class.manages_homedir? end end end @@ -391,7 +391,7 @@ def insync?(current) validate do |value| if value.intern != :absent and value !~ /^\d{4}-\d{2}-\d{2}$/ - raise ArgumentError, "Expiry dates must be YYYY-MM-DD or the string \"absent\"" + raise ArgumentError, _("Expiry dates must be YYYY-MM-DD or the string \"absent\"") end end end @@ -468,9 +468,9 @@ def membership validate do |value| if value =~ /^\d+$/ - raise ArgumentError, "Role names must be provided, not numbers" + raise ArgumentError, _("Role names must be provided, not numbers") end - raise ArgumentError, "Role names must be provided as an array, not a comma-separated list" if value.include?(",") + raise ArgumentError, _("Role names must be provided as an array, not a comma-separated list") if value.include?(",") end end @@ -505,9 +505,9 @@ def membership validate do |value| if value =~ /^\d+$/ - raise ArgumentError, "Auth names must be provided, not numbers" + raise ArgumentError, _("Auth names must be provided, not numbers") end - raise ArgumentError, "Auth names must be provided as an array, not a comma-separated list" if value.include?(",") + raise ArgumentError, _("Auth names must be provided as an array, not a comma-separated list") if value.include?(",") end end @@ -531,9 +531,9 @@ def membership validate do |value| if value =~ /^\d+$/ - raise ArgumentError, "Profile names must be provided, not numbers" + raise ArgumentError, _("Profile names must be provided, not numbers") end - raise ArgumentError, "Profile names must be provided as an array, not a comma-separated list" if value.include?(",") + raise ArgumentError, _("Profile names must be provided as an array, not a comma-separated list") if value.include?(",") end end @@ -555,7 +555,7 @@ def membership end validate do |value| - raise ArgumentError, "Key/value pairs must be separated by an =" unless value.include?("=") + raise ArgumentError, _("Key/value pairs must be separated by an =") unless value.include?("=") end end @@ -589,7 +589,7 @@ def delimiter end validate do |value| - raise ArgumentError, "Attributes value pairs must be separated by an =" unless value.include?("=") + raise ArgumentError, _("Attributes value pairs must be separated by an =") unless value.include?("=") end end @@ -662,14 +662,14 @@ def generate if value.is_a?(Array) value.each do |entry| - raise ArgumentError, "Each entry for purge_ssh_keys must be a string, not a #{entry.class}" unless entry.is_a?(String) + raise ArgumentError, _("Each entry for purge_ssh_keys must be a string, not a #{entry.class}") unless entry.is_a?(String) valid_home = Puppet::Util.absolute_path?(entry) || entry =~ %r{^~/|^%h/} - raise ArgumentError, "Paths to keyfiles must be absolute, not #{entry}" unless valid_home + raise ArgumentError, _("Paths to keyfiles must be absolute, not #{entry}") unless valid_home end return end - raise ArgumentError, "purge_ssh_keys must be true, false, or an array of file names, not #{value.inspect}" + raise ArgumentError, _("purge_ssh_keys must be true, false, or an array of file names, not #{value.inspect}") end munge do |value| @@ -681,14 +681,14 @@ def generate return [] if value == :false home = resource[:home] if value == :true and not home - raise ArgumentError, "purge_ssh_keys can only be true for users with a defined home directory" + raise ArgumentError, _("purge_ssh_keys can only be true for users with a defined home directory") end return [ "#{home}/.ssh/authorized_keys" ] if value == :true # value is an array - munge each value [ value ].flatten.map do |entry| if entry =~ /^~|^%h/ and not home - raise ArgumentError, "purge_ssh_keys value '#{value}' meta character ~ or %h only allowed for users with a defined home directory" + raise ArgumentError, _("purge_ssh_keys value '#{value}' meta character ~ or %h only allowed for users with a defined home directory") end entry.gsub!(/^~\//, "#{home}/") entry.gsub!(/^%h\//, "#{home}/") @@ -702,7 +702,7 @@ def generate validate do |value| if value =~ /^\d+$/ - raise ArgumentError, "Class name must be provided." + raise ArgumentError, _("Class name must be provided.") end end end diff --git a/lib/puppet/type/yumrepo.rb b/lib/puppet/type/yumrepo.rb index 3d531d25f98..c6ef82574f9 100644 --- a/lib/puppet/type/yumrepo.rb +++ b/lib/puppet/type/yumrepo.rb @@ -62,7 +62,7 @@ parsed = URI.parse(value) unless VALID_SCHEMES.include?(parsed.scheme) - raise "Must be a valid URL" + raise _("Must be a valid URL") end end end @@ -79,7 +79,7 @@ parsed = URI.parse(uri) unless VALID_SCHEMES.include?(parsed.scheme) - raise "Must be a valid URL" + raise _("Must be a valid URL") end end end @@ -126,7 +126,7 @@ parsed = URI.parse(uri) unless VALID_SCHEMES.include?(parsed.scheme) - raise "Must be a valid URL" + raise _("Must be a valid URL") end end end @@ -150,7 +150,7 @@ parsed = URI.parse(value) unless VALID_SCHEMES.include?(parsed.scheme) - raise "Must be a valid URL" + raise _("Must be a valid URL") end end end @@ -172,7 +172,7 @@ parsed = URI.parse(value) unless VALID_SCHEMES.include?(parsed.scheme) - raise "Must be a valid URL" + raise _("Must be a valid URL") end end end @@ -258,7 +258,7 @@ validate do |value| next if value.to_s == 'absent' unless (1..99).include?(value.to_i) - fail("Must be within range 1-99") + fail(_("Must be within range 1-99")) end end end @@ -300,7 +300,7 @@ parsed = URI.parse(value) unless VALID_SCHEMES.include?(parsed.scheme) - raise "Must be a valid URL" + raise _("Must be a valid URL") end end end @@ -366,7 +366,7 @@ parsed = URI.parse(value) unless VALID_SCHEMES.include?(parsed.scheme) - raise "Must be a valid URL" + raise _("Must be a valid URL") end end end diff --git a/lib/puppet/type/zone.rb b/lib/puppet/type/zone.rb index 6bed551ca3b..03f5eb6cc46 100644 --- a/lib/puppet/type/zone.rb +++ b/lib/puppet/type/zone.rb @@ -99,7 +99,7 @@ def provider_sync_send(method) warned = false while provider.processing? next if warned - info "Waiting for zone to finish processing" + info _("Waiting for zone to finish processing") warned = true sleep 1 end @@ -196,7 +196,7 @@ def insync?(is) Puppet to move a zone. Consequently this is a readonly property." validate do |value| - raise ArgumentError, "The zone base must be fully qualified" unless value =~ /^\// + raise ArgumentError, _("The zone base must be fully qualified") unless value =~ /^\// end munge do |value| @@ -233,7 +233,7 @@ def insync?(is) validate do |value| unless value !~ /^\// - raise ArgumentError, "Datasets must be the name of a zfs filesystem" + raise ArgumentError, _("Datasets must be the name of a zfs filesystem") end end end @@ -254,7 +254,7 @@ def insync?(is) validate do |value| unless value =~ /^\// - raise ArgumentError, "Inherited filesystems must be fully qualified" + raise ArgumentError, _("Inherited filesystems must be fully qualified") end end end @@ -327,15 +327,15 @@ def insync?(is) def validate_ip(ip, name) IPAddr.new(ip) if ip rescue ArgumentError - self.fail Puppet::Error, "'#{ip}' is an invalid #{name}", $! + self.fail Puppet::Error, _("'#{ip}' is an invalid #{name}"), $! end def validate_exclusive(interface, address, router) return if !interface.nil? and address.nil? - self.fail "only interface may be specified when using exclusive IP stack: #{interface}:#{address}" + self.fail _("only interface may be specified when using exclusive IP stack: #{interface}:#{address}") end def validate_shared(interface, address, router) - self.fail "ip must contain interface name and ip address separated by a \":\"" if interface.nil? or address.nil? + self.fail _("ip must contain interface name and ip address separated by a \":\"") if interface.nil? or address.nil? [address, router].each do |ip| validate_ip(address, "IP address") unless ip.nil? end