module Locale::Driver::Env

def charset # :nodoc:

:nodoc:
* Returns: the system charset.
(LC_ALL > LC_CTYPE > LANG) or return nil.
Gets the charset from environment variables
def charset  # :nodoc:
  [ENV["LC_ALL"], ENV["LC_CTYPE"], ENV["LANG"]].each do |env|
    tag = Private.parse(env)
    next if tag.nil?
    return tag.charset
  end
  nil
end

def locale

Returns: the locale as Locale::Tag::Posix.
Priority order for charset is LC_ALL > LC_CTYPE > LANG.
Priority order except charset is LC_ALL > LC_MESSAGES > LANG.
Gets the locale from environment variable.
def locale
  lc_all = Private.parse(ENV["LC_ALL"])
  return lc_all if lc_all
  lc_messages = Private.parse(ENV["LC_MESSAGES"])
  lang = Private.parse(ENV["LANG"])
  tag = lc_messages || lang
  return nil if tag.nil?
  lc_ctype = Private.parse(ENV["LC_CTYPE"])
  tag.charset = lc_ctype.charset if lc_ctype
  tag
end

def locales

* Returns: an Array of the locale as Locale::Tag::Posix or nil.
Gets the locales from environment variables. (LANGUAGE > LC_ALL > LC_MESSAGES > LANG)
def locales
  return nil if (ENV["LC_ALL"] || ENV["LC_MESSAGES"] || ENV["LANG"]) == "C"
  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