Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Domain Name based i18n : changes for sitemap & url localised #2280

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions core/app/views/refinery/sitemap/index.xml.builder
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,21 @@ xml.urlset "xmlns" => "http://www.sitemaps.org/schemas/sitemap/0.9" do

@locales.each do |locale|
::I18n.locale = locale
# request appropriate host & port depending on i18n mode
localized_domain_name = ::Refinery::I18n.domain_name_for_locale(locale)
host_with_port = (::Refinery::I18n.domain_name_enabled? && localized_domain_name) ?
[localized_domain_name, ":", request.port].join : request.host_with_port
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should just be a lookup method that accepts request as an argument


::Refinery::Page.live.in_menu.includes(:parts).each do |page|
# exclude sites that are external to our own domain.
page_url = if page.url.is_a?(Hash)
# This is how most pages work without being overriden by link_url
page.url.merge({:only_path => false})
elsif page.url.to_s !~ /^http/
# handle relative link_url addresses.
[request.protocol, request.host_with_port, page.url].join
[request.protocol, host_with_port, page.url].join
end

page_url[:host] = localized_domain_name if (localized_domain_name && page_url.is_a?(Hash))
# Add XML entry only if there is a valid page_url found above.
xml.url do
xml.loc refinery.url_for(page_url)
Expand Down
3 changes: 2 additions & 1 deletion pages/lib/refinery/pages/url.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ def url
current_url = page.link_url

if current_url =~ %r{^/} &&
Refinery::I18n.current_frontend_locale != Refinery::I18n.default_frontend_locale
(Refinery::I18n.current_frontend_locale != Refinery::I18n.default_frontend_locale) \
&& !::Refinery::I18n.domain_name_enabled?
current_url = "/#{Refinery::I18n.current_frontend_locale}#{current_url}"
end

Expand Down
18 changes: 18 additions & 0 deletions pages/spec/lib/refinery/pages/url_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,24 @@ module Pages
Url::Localised.new(page).url.should eq("/test")
end
end

context "when current frontend locale != default frontend locale and domain name enabled" do
it "returns unaltered link_url" do
Refinery::I18n.stub(:current_frontend_locale).and_return(:lv)
Refinery::I18n.stub(:default_frontend_locale).and_return(:en)
Refinery::I18n.stub(:domain_name_enabled?).and_return(true)
Url::Localised.new(page).url.should eq("/test")
end
end

context "when current frontend locale != default frontend locale and domain name disabled" do
it "returns link_url prefixed with current frontend locale" do
Refinery::I18n.stub(:current_frontend_locale).and_return(:lv)
Refinery::I18n.stub(:default_frontend_locale).and_return(:en)
Refinery::I18n.stub(:domain_name_enabled?).and_return(false)
Url::Localised.new(page).url.should eq("/lv/test")
end
end
end
end

Expand Down