module Puppet::ModuleTranslations

Public Class Methods

load_from_modulepath(modules) click to toggle source

@api private Loads translation files for each of the specified modules, if present. Requires the modules to have `forge_name` specified. @param [[Module]] modules a list of modules for which to

load translations
   # File lib/puppet/gettext/module_translations.rb
11 def self.load_from_modulepath(modules)
12   modules.each do |mod|
13     next unless mod.forge_name && mod.has_translations?(Puppet::GettextConfig.current_locale)
14 
15     module_name = mod.forge_name.tr('/', '-')
16     if Puppet::GettextConfig.load_translations(module_name, mod.locale_directory, :po)
17       Puppet.debug { "Loaded translations for #{module_name}." }
18     elsif Puppet::GettextConfig.gettext_loaded?
19       Puppet.debug { "Could not find translation files for #{module_name} at #{mod.locale_directory}. Skipping translation initialization." }
20     else
21       Puppet.warn_once("gettext_unavailable", "gettext_unavailable", "No gettext library found, skipping translation initialization.")
22     end
23   end
24 end
load_from_vardir(vardir) click to toggle source

@api private Loads translation files that have been pluginsync'd for modules from the $vardir. @param [String] vardir the path to Puppet's vardir

   # File lib/puppet/gettext/module_translations.rb
30 def self.load_from_vardir(vardir)
31   locale = Puppet::GettextConfig.current_locale
32   Dir.glob("#{vardir}/locales/#{locale}/*.po") do |f|
33     module_name = File.basename(f, ".po")
34     if Puppet::GettextConfig.load_translations(module_name, File.join(vardir, "locales"), :po)
35       Puppet.debug { "Loaded translations for #{module_name}." }
36     elsif Puppet::GettextConfig.gettext_loaded?
37       Puppet.debug { "Could not load translations for #{module_name}." }
38     else
39       Puppet.warn_once("gettext_unavailable", "gettext_unavailable", "No gettext library found, skipping translation initialization.")
40     end
41   end
42 end