Class: Ramaze::Helper::Localize::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/ramaze/helper/localize.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#requestObject

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

#parseObject



117
118
119
# File 'lib/ramaze/helper/localize.rb', line 117

def parse
  parse_params || parse_session || parse_cookie || parse_header
end


131
132
133
134
# File 'lib/ramaze/helper/localize.rb', line 131

def parse_cookie(key = 'lang')
  return unless lang = request.cookies[key]
  ::Locale::Tag.parse(lang)
end

#parse_headerObject



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