Module: Locale::Driver::Env
- Defined in:
- lib/locale/driver/env.rb
Overview
Locale::Driver::Env module. Detect the user locales and the charset. All drivers(except CGI) refer environment variables first and use it as the locale if it’s defined. This is a low-level module. Application shouldn’t use this directly.
Class Method Summary collapse
-
.charset ⇒ Object
Gets the charset from environment variable or return nil.
-
.locale ⇒ Object
Gets the locale from environment variable.
-
.locales ⇒ Object
Gets the locales from environment variables.
Class Method Details
.charset ⇒ Object
Gets the charset from environment variable or return nil.
-
Returns: the system charset.
66 67 68 69 70 71 72 |
# File 'lib/locale/driver/env.rb', line 66 def charset # :nodoc: if loc = locale loc.charset else nil end end |
.locale ⇒ Object
Gets the locale from environment variable. (LC_ALL > LC_CTYPES > LANG) Returns: the locale as Locale::Tag::Posix.
39 40 41 42 43 44 45 46 47 |
# File 'lib/locale/driver/env.rb', line 39 def locale # At least one environment valiables should be set on *nix system. [ENV["LC_ALL"], ENV["LC_CTYPES"], ENV["LANG"]].each do |loc| if loc != nil and loc.size > 0 return Locale::Tag::Posix.parse(loc) end end nil end |
.locales ⇒ Object
Gets the locales from environment variables. (LANGUAGE > LC_ALL > LC_CTYPES > LANG)
-
Returns: an Array of the locale as Locale::Tag::Posix or nil.
51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/locale/driver/env.rb', line 51 def locales locales = ENV["LANGUAGE"] if (locales != nil and locales.size > 0) locs = locales.split(/:/).collect{|v| Locale::Tag::Posix.parse(v)}.compact if locs.size > 0 return Locale::TagList.new(locs) end elsif (loc = locale) return Locale::TagList.new([loc]) end nil end |