Module: Locale::SystemBase

Included in:
SystemCGI, SystemJRuby, SystemPosix, SystemWin32
Defined in:
lib/locale/base.rb

Overview

Locale::SystemBase module. This module overrides from other concrete modules. This is a low-level class. Application shouldn’t use this directly.

Constant Summary collapse

@@default_locale =
Locale::Object.new("C", nil, "UTF-8")

Instance Method Summary collapse

Instance Method Details

#charsetObject

Gets the charset of the locale.

  • locale: Locale::Object

  • Returns: the charset of the locale



54
55
56
57
# File 'lib/locale/base.rb', line 54

def charset
  # locale parameter is ignored now.
  system.charset
end

#default_localeObject

:nodoc:



19
20
21
# File 'lib/locale/base.rb', line 19

def default_locale  # :nodoc:
  @@default_locale
end

#get_charset(locale) ⇒ Object

Gets the charset of the locale.

  • locale: Locale::Object

  • Returns the charset of the locale



26
27
28
# File 'lib/locale/base.rb', line 26

def get_charset(locale)
  locale.charset || @@default_locale.charset
end

#locale_from_envObject

Gets the system locale using setlocale and nl_langinfo.

  • Returns the system locale (Locale::Object).



32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/locale/base.rb', line 32

def locale_from_env
  locale = nil
  # At least one environment valiables should be set on *nix system.
  [ENV["LC_ALL"], ENV["LC_MESSAGES"], ENV["LANG"]].each do |loc|
	if loc != nil and loc.size > 0
	  locale = Locale::Object.new(loc)
	  locale.charset ||= get_charset(locale)
	  break
	end
  end
  locale
end

#systemObject

Gets the system locale.

  • Returns the system locale (Locale::Object)



47
48
49
# File 'lib/locale/base.rb', line 47

def system
  locale_from_env || default_locale
end