Skip to content

Commit

Permalink
Merge pull request #6259 from Magisus/config-yaml-exception
Browse files Browse the repository at this point in the history
(PUP-8009) Avoid throwing an exception when gettext config is missing
  • Loading branch information
MikaelSmith committed Oct 4, 2017
2 parents 1d56d73 + 95689c2 commit 80ace36
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
11 changes: 7 additions & 4 deletions lib/puppet/gettext/config.rb
Expand Up @@ -57,19 +57,22 @@ def self.disable_gettext
# @param path [String] to gettext config file
# @param file_format [Symbol] translation file format to use, either :po or :mo
# @return true if initialization succeeded, false otherwise
def self.initialize(conf_file_location, file_format)
def self.initialize(conf_file_dir, file_format)
return false if @gettext_disabled || !@gettext_loaded

unless file_format == :po || file_format == :mo
raise Puppet::Error, "Unsupported translation file format #{file_format}; please use :po or :mo"
end

if conf_file_location && Puppet::FileSystem.exist?(conf_file_location)
return false if conf_file_dir.nil?

conf_file = File.join(conf_file_dir, "config.yaml")
if Puppet::FileSystem.exist?(conf_file)
if GettextSetup.method(:initialize).parameters.count == 1
# For use with old gettext-setup gem versions, will load PO files only
GettextSetup.initialize(conf_file_location)
GettextSetup.initialize(conf_file_dir)
else
GettextSetup.initialize(conf_file_location, :file_format => file_format)
GettextSetup.initialize(conf_file_dir, :file_format => file_format)
end
# Only change this once.
# Because negotiate_locales will only return a non-default locale if
Expand Down
6 changes: 3 additions & 3 deletions spec/unit/module_spec.rb
Expand Up @@ -225,10 +225,10 @@
mod_dir = "#{@modpath}/#{mod_name}"
metadata_file = "#{mod_dir}/metadata.json"
tasks_dir = "#{mod_dir}/tasks"
locales_dir = "#{mod_dir}/locales"
locale_config = "#{mod_dir}/locales/config.yaml"
Puppet::FileSystem.stubs(:exist?).with(metadata_file).returns true
# Skip checking for translation config file
Puppet::FileSystem.stubs(:exist?).with(locales_dir).returns false
Puppet::FileSystem.stubs(:exist?).with(locale_config).returns false
end
mod = PuppetSpec::Modules.create(
'test_gte_req',
Expand Down Expand Up @@ -465,7 +465,7 @@
}
}
File.open(config_path, 'w') { |file| file.write(config.to_yaml) }
Puppet::FileSystem.stubs(:exist?).with(locale_dir).returns(true)
Puppet::FileSystem.stubs(:exist?).with(config_path).returns(true)

mod_obj.initialize_i18n

Expand Down

0 comments on commit 80ace36

Please sign in to comment.