Skip to content

A platform for community discussion. Free, open, simple.

DEV: Force full refresh from language switcher (#33522)

Natalie Tay0a242221fc12
diff --git a/app/assets/javascripts/discourse/app/components/language-switcher.gjs b/app/assets/javascripts/discourse/app/components/language-switcher.gjs
index e0300fc391d..1c23e975386 100644
--- a/app/assets/javascripts/discourse/app/components/language-switcher.gjs
+++ b/app/assets/javascripts/discourse/app/components/language-switcher.gjs
@@ -16,9 +16,9 @@ export default class LanguageSwitcher extends Component {
async changeLocale(locale) {
cookie("locale", locale, { path: "/" });
this.dMenu.close();
- // we need a hard refresh here for the locale to take effect
- // window.location.reload();
- this.router.refresh();
+ // content should switch immediately,
+ // but we need a hard refresh here for controls to switch to the new locale
+ window.location.reload();
}
@action
diff --git a/spec/system/anon_language_switcher_spec.rb b/spec/system/anon_language_switcher_spec.rb
index 333e47743a8..919971621a1 100644
--- a/spec/system/anon_language_switcher_spec.rb
+++ b/spec/system/anon_language_switcher_spec.rb
@@ -3,14 +3,27 @@
RSpec.describe "Anonymous user language switcher", type: :system do
SWITCHER_SELECTOR = "button[data-identifier='language-switcher']"
- let(:topic_page) { PageObjects::Pages::Topic.new }
+ let(:topic_list) { PageObjects::Components::TopicList.new }
let(:switcher) { PageObjects::Components::DMenu.new(SWITCHER_SELECTOR) }
fab!(:japanese_user) { Fabricate(:user, locale: "ja") }
- fab!(:topic) do
- topic = Fabricate(:topic, title: "Life strategies from The Art of War")
- Fabricate(:post, topic:)
- topic
+
+ fab!(:topic) { Fabricate(:topic, title: "Life strategies from The Art of War", locale: "en") }
+ fab!(:post_1) do
+ Fabricate(
+ :post,
+ topic:,
+ locale: "en",
+ raw: "The masterpiece isn’t just about military strategy",
+ )
+ end
+
+ fab!(:topic_localization) do
+ Fabricate(:topic_localization, topic:, locale: "ja", fancy_title: "孫子兵法からの人生戦略")
+ end
+
+ fab!(:post_localization) do
+ Fabricate(:post_localization, post: post_1, locale: "ja", cooked: "傑作は単なる軍事戦略についてではありません")
end
before do
@@ -35,11 +48,16 @@ RSpec.describe "Anonymous user language switcher", type: :system do
expect(switcher).to have_content("日本語")
expect(switcher).to have_content("Español")
- SiteSetting.content_localization_supported_locales = "es"
+ SiteSetting.content_localization_supported_locales = "ja"
visit("/")
switcher.expand
- expect(switcher).not_to have_content("日本語")
+ expect(switcher).not_to have_content("Español")
+ switcher.option("[data-menu-option-id='ja']").click
+ expect(topic_list).to have_content("孫子兵法からの人生戦略")
+ I18n.with_locale("ja") do
+ expect(page.find("#navigation-bar")).to have_content(I18n.t("js.filters.latest.title"))
+ end
sign_in(japanese_user)
expect(page).not_to have_css(SWITCHER_SELECTOR)