Class: RoutingFilter::Language
- Inherits:
-
Filter
- Object
- Filter
- RoutingFilter::Language
show all
- Defined in:
- lib/routing_filter/filters/language.rb
Constant Summary
collapse
- @@include_default_language =
true
Instance Attribute Summary
Attributes inherited from Filter
#next, #options, #previous
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Filter
#initialize, #run, #run_reverse
Class Method Details
.include_default_language? ⇒ Boolean
31
32
33
|
# File 'lib/routing_filter/filters/language.rb', line 31
def include_default_language?
@@include_default_language
end
|
.languages ⇒ Object
35
36
37
|
# File 'lib/routing_filter/filters/language.rb', line 35
def languages
@@languages ||= I18n.available_locales.map{|l| l.to_sym}
end
|
.languages=(languages) ⇒ Object
39
40
41
|
# File 'lib/routing_filter/filters/language.rb', line 39
def languages=(languages)
@@languages = languages.map(&:to_sym)
end
|
.languages_pattern ⇒ Object
redefine original method to support locales like en-RU etc
44
45
46
|
# File 'lib/routing_filter/filters/language.rb', line 44
def languages_pattern
@@languages_pattern ||= %r(^/(#{self.languages.map{|l| Regexp.escape(l.to_s).sub(/[A-Z]{2}$/,"[A-Z]{2}")}.join('|')})(?=/|$))
end
|
Instance Method Details
#around_generate(*args, &block) ⇒ Object
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
# File 'lib/routing_filter/filters/language.rb', line 57
def around_generate(*args, &block)
params = args.
language = params[:language] language = I18n.locale if language.nil? language = I18n.lang_tag(language) if language
language = nil unless valid_language?(language)
params.delete(:language) unless configatron.prevent_deleting_language_param
args << params
yield.tap do |result|
prepend_segment!(result, language) if prepend_language?(language)
end
end
|
#around_recognize(path, env, &block) ⇒ Object
50
51
52
53
54
55
|
# File 'lib/routing_filter/filters/language.rb', line 50
def around_recognize(path, env, &block)
language = (self.class.languages_pattern, path) yield.tap do |params| params[:language] = language if language end
end
|