lib/wcc/contentful/model/menu_button.rb in wcc-contentful-app-1.4.0.rc1 vs lib/wcc/contentful/model/menu_button.rb in wcc-contentful-app-1.4.0.rc2
- old
+ new
@@ -16,14 +16,27 @@
return external_link if external_link
url = (link&.try(:slug) || link&.try(:url))
url = URI(url || '')
- url.path = "/#{sys.locale}#{url.path}" if sys.locale != WCC::Contentful.configuration.default_locale
+ url = rewrite_to_locale(url, sys.locale) if default_locale && sys.locale != default_locale
+
url.fragment = fragment if fragment.present?
url.to_s
end
def fragment
WCC::Contentful::App::SectionHelper.section_id(section_link) if section_link
+ end
+
+ private
+
+ def default_locale
+ WCC::Contentful.configuration&.default_locale
+ end
+
+ def rewrite_to_locale(uri, locale)
+ uri = URI(uri)
+ uri.path = File.join("/#{locale}", uri.path)
+ uri.to_s
end
end