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.
53 54 55 56 57 58 59 |
# File 'lib/locale/driver/env.rb', line 53 def charset # :nodoc: if loc = locale loc.charset else nil end end |
.locale ⇒ Object
Gets the locale from environment variable. (LC_ALL > LC_MESSAGES > LANG) Returns: the locale as Locale::Tag::Posix.
29 30 31 32 33 34 35 36 37 |
# File 'lib/locale/driver/env.rb', line 29 def locale # 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 return Locale::Tag::Posix.parse(loc) end end nil end |
.locales ⇒ Object
Gets the locales from environment variables. (LANGUAGE > LC_ALL > LC_MESSAGES > LANG)
-
Returns: an Array of the locale as Locale::Tag::Posix or nil.
41 42 43 44 45 46 47 48 49 |
# File 'lib/locale/driver/env.rb', line 41 def locales if (locales = ENV["LANGUAGE"]) Locale::TagList.new(locales.split(/:/).collect{|v| Locale::Tag::Posix.parse(v)}) elsif (loc = locale) Locale::TagList.new([loc]) else nil end end |