Module | Locale::SystemCGI |
In: |
lib/locale/cgi.rb
|
Locale::System module for CGI. This is a low-level class. Application shouldn‘t use this directly.
Gets the CGI object. If it is nil, returns new CGI object.
# File lib/locale/cgi.rb, line 68 68: def cgi 69: @@cgi = CGI.new unless @@cgi 70: @@cgi 71: end
Sets a CGI object.
# File lib/locale/cgi.rb, line 61 61: def cgi=(cgi_) 62: set_cgi(cgi_) 63: cgi_ 64: end
Gets the default Locale::Object.
# File lib/locale/cgi.rb, line 75 75: def default_locale 76: @@default_locale 77: end
Sets a CGI object.
# File lib/locale/cgi.rb, line 53 53: def set_cgi(cgi_) 54: @@cgi = cgi_ 55: self 56: end
Gets the default locale using setlocale and nl_langinfo.
# File lib/locale/cgi.rb, line 26 26: def system 27: return @@default_locale unless @@cgi 28: cgi_ = cgi 29: if cgi_.has_key?("lang") and ret = cgi_["lang"] and ret.size > 0 30: elsif ret = cgi_.cookies["lang"][0] 31: elsif lang = cgi_.accept_language and lang.size > 0 32: num = lang.index(/;|,/) 33: ret = num ? lang[0, num] : lang 34: else 35: ret = @@default_locale.to_str 36: end 37: 38: codesets = cgi_.accept_charset 39: if codesets and codesets.size > 0 40: num = codesets.index(',') 41: codeset = num ? codesets[0, num] : codesets 42: codeset = @@default_locale.charset if codeset == "*" 43: else 44: codeset = @@default_locale.charset 45: end 46: Locale::Object.new(ret, nil, codeset) 47: end