3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
# File 'app/helpers/amalgam/url_helper.rb', line 3
def locale_url(locale)
available_locales = ::I18n::available_locales.collect{|m| m.to_s.downcase}
path_list = request.fullpath.split('/')
if path_list.present?
if available_locales.include?(path_list[1].downcase)
path_list[1] = locale
return "#{request.protocol}#{request.host_with_port}#{path_list.join('/')}"
end
else
return "#{request.protocol}#{request.host_with_port}/#{locale}"
end
if locale_param = request.fullpath.match(/locale=[\w|-]*/)
url = "#{request.protocol}#{request.host_with_port}#{request.fullpath}"
url[locale_param[0]] = "locale=#{locale}"
return url
end
domain_list = request.host_with_port.split('.')
if available_locales.include?(domain_list.first.downcase)
domain_list[0] = locale
return "#{request.protocol}#{domain_list.join('.')}#{request.fullpath}"
end
if request.fullpath.include?('?')
return "#{request.protocol}#{request.host_with_port}#{request.fullpath}&locale=#{locale}"
else
return "#{request.protocol}#{request.host_with_port}#{request.fullpath}?locale=#{locale}"
end
end
|