Skip to content

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

FEATURE: Reset the 'show original content' status when the user changes content language (#36620)

Natalie Tay5a8a0351fcc7
diff --git a/frontend/discourse/app/components/language-switcher.gjs b/frontend/discourse/app/components/language-switcher.gjs
index b153744ec5c..2dd6b38469f 100644
--- a/frontend/discourse/app/components/language-switcher.gjs
+++ b/frontend/discourse/app/components/language-switcher.gjs
@@ -5,7 +5,9 @@ import { service } from "@ember/service";
import DButton from "discourse/components/d-button";
import DropdownMenu from "discourse/components/dropdown-menu";
import DMenu from "discourse/float-kit/components/d-menu";
-import cookie from "discourse/lib/cookie";
+import cookie, { removeCookie } from "discourse/lib/cookie";
+
+const SHOW_ORIGINAL_COOKIE = "content-localization-show-original";
export default class LanguageSwitcher extends Component {
@service siteSettings;
@@ -21,6 +23,8 @@ export default class LanguageSwitcher extends Component {
cookie("locale", locale, { path: "/" });
}
+ removeCookie(SHOW_ORIGINAL_COOKIE, { path: "/" });
+
this.dMenu.close();
// content should switch immediately,
// but we need a hard refresh here for controls to switch to the new locale
diff --git a/spec/system/content_localization_language_switcher_spec.rb b/spec/system/content_localization_language_switcher_spec.rb
index 75bcef5ce0f..d68e4873fbd 100644
--- a/spec/system/content_localization_language_switcher_spec.rb
+++ b/spec/system/content_localization_language_switcher_spec.rb
@@ -2,6 +2,7 @@
describe "Content localization language switcher", type: :system do
SWITCHER_SELECTOR = "button[data-identifier='language-switcher']"
+ TOGGLE_LOCALIZE_BUTTON_SELECTOR = "button.btn-toggle-localized-content"
let(:topic_list) { PageObjects::Components::TopicList.new }
let(:switcher) { PageObjects::Components::DMenu.new(SWITCHER_SELECTOR) }
@@ -120,6 +121,34 @@ describe "Content localization language switcher", type: :system do
end
end
+ it "resets localized content toggle after changing languages" do
+ SiteSetting.content_localization_language_switcher = "all"
+
+ visit("/t/#{topic.id}")
+
+ select_language("ja")
+
+ expect(topic_list).to have_content("孫子兵法からの人生戦略")
+ expect(page.find(TOGGLE_LOCALIZE_BUTTON_SELECTOR)["title"]).to eq(
+ I18n.t("js.content_localization.toggle_localized.translated"),
+ )
+
+ page.find(TOGGLE_LOCALIZE_BUTTON_SELECTOR).click
+ expect(topic_list).to have_content("Life strategies from The Art of War")
+ expect(page.find(TOGGLE_LOCALIZE_BUTTON_SELECTOR)["title"]).to eq(
+ I18n.t("js.content_localization.toggle_localized.not_translated"),
+ )
+
+ select_language("es")
+
+ expect(topic_list).to have_content("Estrategias de vida de El arte de la guerra")
+ I18n.with_locale("es") do
+ expect(page.find(TOGGLE_LOCALIZE_BUTTON_SELECTOR)["title"]).to eq(
+ I18n.t("js.content_localization.toggle_localized.translated"),
+ )
+ end
+ end
+
def select_language(locale)
switcher.expand
switcher.option("[data-menu-option-id='#{locale}']").click