Merge pull request #4850 from consul/changing_language_text_direction
Disable Turbolinks for languages with different text direction
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
class Layout::LocaleSwitcherComponent < ApplicationComponent
|
class Layout::LocaleSwitcherComponent < ApplicationComponent
|
||||||
delegate :name_for_locale, :link_list, :current_path_with_query_params, to: :helpers
|
delegate :name_for_locale, :link_list, :current_path_with_query_params, :rtl?, to: :helpers
|
||||||
|
|
||||||
def render?
|
def render?
|
||||||
locales.size > 1
|
locales.size > 1
|
||||||
@@ -29,7 +29,8 @@ class Layout::LocaleSwitcherComponent < ApplicationComponent
|
|||||||
name_for_locale(locale),
|
name_for_locale(locale),
|
||||||
current_path_with_query_params(locale: locale),
|
current_path_with_query_params(locale: locale),
|
||||||
locale == I18n.locale,
|
locale == I18n.locale,
|
||||||
lang: locale
|
lang: locale,
|
||||||
|
data: { turbolinks: rtl?(I18n.locale) == rtl?(locale) }
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -6,8 +6,8 @@ module ApplicationHelper
|
|||||||
url_for(request.query_parameters.merge(query_parameters).merge(only_path: true))
|
url_for(request.query_parameters.merge(query_parameters).merge(only_path: true))
|
||||||
end
|
end
|
||||||
|
|
||||||
def rtl?
|
def rtl?(locale = I18n.locale)
|
||||||
%i[ar fa he].include?(I18n.locale)
|
%i[ar fa he].include?(locale)
|
||||||
end
|
end
|
||||||
|
|
||||||
def markdown(text)
|
def markdown(text)
|
||||||
|
|||||||
@@ -74,4 +74,27 @@ describe Layout::LocaleSwitcherComponent do
|
|||||||
expect(page).to have_css "[aria-current]", exact_text: "English"
|
expect(page).to have_css "[aria-current]", exact_text: "English"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "when the target language has a different text direction than the current language" do
|
||||||
|
let!(:default_locales) { I18n.available_locales }
|
||||||
|
|
||||||
|
before do
|
||||||
|
I18n.available_locales = %i[ar en]
|
||||||
|
I18n.reload!
|
||||||
|
end
|
||||||
|
|
||||||
|
after do
|
||||||
|
I18n.available_locales = default_locales
|
||||||
|
I18n.reload!
|
||||||
|
end
|
||||||
|
|
||||||
|
it "disables Turbolinks for language links" do
|
||||||
|
render_inline component
|
||||||
|
|
||||||
|
expect(page).to have_link "عربى", href: "/?locale=ar"
|
||||||
|
expect(page).to have_css "[href='/?locale=ar'][data-turbolinks=false]"
|
||||||
|
expect(page).to have_link "English", href: "/?locale=en"
|
||||||
|
expect(page).to have_css "[href='/?locale=en'][data-turbolinks=true]"
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user