Class: Ramaze::Helper::Localize::Parser
- Inherits:
-
Object
- Object
- Ramaze::Helper::Localize::Parser
- Defined in:
- lib/ramaze/helper/localize.rb
Instance Attribute Summary collapse
-
#request ⇒ Object
Returns the value of attribute request.
Instance Method Summary collapse
-
#initialize(request) ⇒ Parser
constructor
A new instance of Parser.
- #locales(fallback = nil) ⇒ Object
- #parse ⇒ Object
- #parse_cookie(key = 'lang') ⇒ Object
- #parse_header ⇒ Object
- #parse_params(key = 'lang') ⇒ Object
- #parse_session(key = :lang) ⇒ Object
Constructor Details
#initialize(request) ⇒ Parser
Returns a new instance of Parser.
108 109 110 |
# File 'lib/ramaze/helper/localize.rb', line 108 def initialize(request) @request = request end |
Instance Attribute Details
#request ⇒ Object
Returns the value of attribute request.
106 107 108 |
# File 'lib/ramaze/helper/localize.rb', line 106 def request @request end |
Instance Method Details
#locales(fallback = nil) ⇒ Object
112 113 114 115 |
# File 'lib/ramaze/helper/localize.rb', line 112 def locales(fallback = nil) locales = [parse, fallback].flatten.uniq ::Locale::TagList.new(locales) end |
#parse ⇒ Object
117 118 119 |
# File 'lib/ramaze/helper/localize.rb', line 117 def parse parse_params || parse_session || || parse_header end |
#parse_cookie(key = 'lang') ⇒ Object
131 132 133 134 |
# File 'lib/ramaze/helper/localize.rb', line 131 def (key = 'lang') return unless lang = request.[key] ::Locale::Tag.parse(lang) end |
#parse_header ⇒ Object
136 137 138 139 |
# File 'lib/ramaze/helper/localize.rb', line 136 def parse_header request.accept_language.map{|lang| ::Locale::Tag.parse(lang) } end |
#parse_params(key = 'lang') ⇒ Object
121 122 123 124 |
# File 'lib/ramaze/helper/localize.rb', line 121 def parse_params(key = 'lang') return unless lang = request.params[key] ::Locale::Tag.parse(lang) end |
#parse_session(key = :lang) ⇒ Object
126 127 128 129 |
# File 'lib/ramaze/helper/localize.rb', line 126 def parse_session(key = :lang) return unless lang = Current.session[key] ::Locale::Tag.parse(lang) end |