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.



98
99
100
# File 'lib/ramaze/helper/localize.rb', line 98

def initialize(request)
  @request = request
end

Instance Attribute Details

#requestObject

Returns the value of attribute request.



96
97
98
# File 'lib/ramaze/helper/localize.rb', line 96

def request
  @request
end

Instance Method Details

#locales(fallback = nil) ⇒ Object



102
103
104
105
# File 'lib/ramaze/helper/localize.rb', line 102

def locales(fallback = nil)
  locales = [parse, fallback].flatten.uniq
  ::Locale::TagList.new(locales)
end

#parseObject



107
108
109
# File 'lib/ramaze/helper/localize.rb', line 107

def parse
  parse_params || parse_cookie || parse_header
end


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

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

#parse_headerObject



121
122
123
124
# File 'lib/ramaze/helper/localize.rb', line 121

def parse_header
  request.accept_language_with_weight.map{|lang|
    ::Locale::Tag.parse(lang) }
end

#parse_params(key = 'lang') ⇒ Object



111
112
113
114
# File 'lib/ramaze/helper/localize.rb', line 111

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