Module: Puppet::ModuleTranslations

Defined in:
lib/puppet/gettext/module_translations.rb

Class Method Summary collapse

Class Method Details

.load_from_modulepath(modules) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Loads translation files for each of the specified modules, if present. Requires the modules to have `forge_name` specified.


10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/puppet/gettext/module_translations.rb', line 10

def self.load_from_modulepath(modules)
  modules.each do |mod|
    next unless mod.forge_name && mod.has_translations?(Puppet::GettextConfig.current_locale)

    module_name = mod.forge_name.tr('/', '-')
    if Puppet::GettextConfig.load_translations(module_name, mod.locale_directory, :po)
      Puppet.debug "Loaded translations for #{module_name}."
    elsif Puppet::GettextConfig.gettext_loaded?
      Puppet.debug "Could not find translation files for #{module_name} at #{mod.locale_directory}. Skipping translation initialization."
    else
      Puppet.warn_once("gettext_unavailable", "gettext_unavailable", "No gettext library found, skipping translation initialization.")
    end
  end
end

.load_from_vardir(vardir) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Loads translation files that have been pluginsync'd for modules from the $vardir.


29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/puppet/gettext/module_translations.rb', line 29

def self.load_from_vardir(vardir)
  locale = Puppet::GettextConfig.current_locale
  Dir.glob("#{vardir}/locales/#{locale}/*.po") do |f|
    module_name = File.basename(f, ".po")
    if Puppet::GettextConfig.load_translations(module_name, File.join(vardir, "locales"), :po)
      Puppet.debug "Loaded translations for #{module_name}."
    elsif Puppet::GettextConfig.gettext_loaded?
      Puppet.debug "Could not load translations for #{module_name}."
    else
      Puppet.warn_once("gettext_unavailable", "gettext_unavailable", "No gettext library found, skipping translation initialization.")
    end
  end
end