Class: ActionView::PathSet

Inherits:
Array
  • Object
show all
Defined in:
lib/locale_rails/action_view.rb

Instance Method Summary collapse

Instance Method Details

#_find_template_internal(file_name, format, html_fallback = false) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/locale_rails/action_view.rb', line 17

def _find_template_internal(file_name, format, html_fallback = false)
  begin
    return find_template_without_locale_rails(file_name, format, html_fallback)
  rescue MissingTemplate => e
  end
  nil
end

#find_template_with_locale_rails(original_template_path, format = nil, html_fallback = true) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/locale_rails/action_view.rb', line 25

def find_template_with_locale_rails(original_template_path, format = nil, html_fallback = true)
  return original_template_path if original_template_path.respond_to?(:render)

  path = original_template_path.sub(/^\//, '')
  if m = path.match(/(.*)\.(\w+)$/)
    template_file_name, template_file_extension = m[1], m[2]
  else
    template_file_name = path
  end
 
  default = Locale.default.to_common
  Locale.candidates.each do |v|
    file_name = "#{template_file_name}_#{v}"
    ret = _find_template_internal(file_name, format)
    return ret if ret
    if v == default
      # When the user locale is the default locale, find no locale file such as index.html.erb.
      ret = _find_template_internal(template_file_name, format)
    end
    return ret if ret
  end
  find_template_without_locale_rails(original_template_path, format, html_fallback)
end