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
10 def self.load_from_modulepath(modules)
11   modules.each do |mod|
12     next unless mod.forge_name && mod.has_translations?(Puppet::GettextConfig.current_locale)
13 
14     module_name = mod.forge_name.tr('/', '-')
15     if Puppet::GettextConfig.load_translations(module_name, mod.locale_directory, :po)
16       Puppet.debug { "Loaded translations for #{module_name}." }
17     elsif Puppet::GettextConfig.gettext_loaded?
18       Puppet.debug { "Could not find translation files for #{module_name} at #{mod.locale_directory}. Skipping translation initialization." }
19     else
20       Puppet.warn_once("gettext_unavailable", "gettext_unavailable", "No gettext library found, skipping translation initialization.")
21     end
22   end
23 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
29 def self.load_from_vardir(vardir)
30   locale = Puppet::GettextConfig.current_locale
31   Dir.glob("#{vardir}/locales/#{locale}/*.po") do |f|
32     module_name = File.basename(f, ".po")
33     if Puppet::GettextConfig.load_translations(module_name, File.join(vardir, "locales"), :po)
34       Puppet.debug { "Loaded translations for #{module_name}." }
35     elsif Puppet::GettextConfig.gettext_loaded?
36       Puppet.debug { "Could not load translations for #{module_name}." }
37     else
38       Puppet.warn_once("gettext_unavailable", "gettext_unavailable", "No gettext library found, skipping translation initialization.")
39     end
40   end
41 end