Module: Puppet::GettextConfig
- Defined in:
- lib/puppet/gettext/config.rb
Constant Summary collapse
- LOCAL_PATH =
File.absolute_path('../../../locales', File.dirname(__FILE__))
- POSIX_PATH =
File.absolute_path('../../../../../share/locale', File.dirname(__FILE__))
- WINDOWS_PATH =
File.absolute_path('../../../../../../../puppet/share/locale', File.dirname(__FILE__))
Class Method Summary collapse
-
.initialize(conf_file_location, file_format) ⇒ Object
Attempt to initialize the gettext-setup gem.
-
.puppet_locale_path ⇒ String
Search for puppet gettext config files.
-
.translation_mode(conf_path) ⇒ Symbol
Determine which translation file format to use.
Class Method Details
.initialize(conf_file_location, file_format) ⇒ Object
Attempt to initialize the gettext-setup gem
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/puppet/gettext/config.rb', line 37 def self.initialize(conf_file_location, file_format) unless file_format == :po || file_format == :mo raise Puppet::Error, "Unsupported translation file format #{file_format}; please use :po or :mo" end begin require 'gettext-setup' require 'locale' if conf_file_location && File.exists?(conf_file_location) 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) else GettextSetup.initialize(conf_file_location, :file_format => file_format) end # Only change this once. # Because negotiate_locales will only return a non-default locale if # the system locale matches a translation set actually available for the # given gettext project, we don't want this to get set back to default if # we load a module that doesn't have translations, but Puppet does have # translations for the user's locale. if FastGettext.locale == GettextSetup.default_locale FastGettext.locale = GettextSetup.negotiate_locale(Locale.current.language) end true else false end rescue LoadError false end end |
.puppet_locale_path ⇒ String
Search for puppet gettext config files
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/puppet/gettext/config.rb', line 10 def self.puppet_locale_path if File.exist?(LOCAL_PATH) return LOCAL_PATH elsif Puppet::Util::Platform.windows? && File.exist?(WINDOWS_PATH) return WINDOWS_PATH elsif !Puppet::Util::Platform.windows? && File.exist?(POSIX_PATH) return POSIX_PATH else nil end end |
.translation_mode(conf_path) ⇒ Symbol
Determine which translation file format to use
25 26 27 28 29 30 31 |
# File 'lib/puppet/gettext/config.rb', line 25 def self.translation_mode(conf_path) if WINDOWS_PATH == conf_path || POSIX_PATH == conf_path return :mo else return :po end end |