A platform for community discussion. Free, open, simple.
DEV: Remove per topic toggle (#40869)
Natalie Taye1b9103c3823
diff --git a/app/assets/stylesheets/common/base/embed-mode.scss b/app/assets/stylesheets/common/base/embed-mode.scssindex d538217426d..b47e078caac 100644--- a/app/assets/stylesheets/common/base/embed-mode.scss+++ b/app/assets/stylesheets/common/base/embed-mode.scss@@ -133,8 +133,7 @@ body.embed-mode {}// Hide admin menu in the progress bar for embed context- #topic-progress-wrapper .topic-admin-menu-trigger,- #topic-progress-wrapper .btn-toggle-localized-content {+ #topic-progress-wrapper .topic-admin-menu-trigger {display: none;}diff --git a/app/assets/stylesheets/common/base/topic-footer.scss b/app/assets/stylesheets/common/base/topic-footer.scssindex d28b1d56faf..2ce0311e39c 100644--- a/app/assets/stylesheets/common/base/topic-footer.scss+++ b/app/assets/stylesheets/common/base/topic-footer.scss@@ -135,16 +135,11 @@width: auto;margin-top: var(--border-offset);- .btn-toggle-localized-content,.topic-admin-menu-trigger {border-radius: 0;background: var(--secondary);border: 1px solid var(--primary-low);}-- .topic-admin-menu-trigger + .btn-toggle-localized-content {- margin-left: var(--border-offset);- }}}diff --git a/app/assets/stylesheets/common/base/topic.scss b/app/assets/stylesheets/common/base/topic.scssindex 9f946b9972a..9b8064e9034 100644--- a/app/assets/stylesheets/common/base/topic.scss+++ b/app/assets/stylesheets/common/base/topic.scss@@ -28,11 +28,6 @@.topic-navigation {overflow-anchor: none;-- .btn-toggle-localized-content.--active {- --d-button-default-icon-color: var(--tertiary);- --d-button-default-icon-color--hover: var(--primary-low);- }}// timelinediff --git a/app/assets/stylesheets/common/base/uc-modernize-foundation-theme/buttons-controls.scss b/app/assets/stylesheets/common/base/uc-modernize-foundation-theme/buttons-controls.scssindex 023d936fd9e..061b7b45e01 100644--- a/app/assets/stylesheets/common/base/uc-modernize-foundation-theme/buttons-controls.scss+++ b/app/assets/stylesheets/common/base/uc-modernize-foundation-theme/buttons-controls.scss@@ -8,11 +8,6 @@--d-button-default-text-color: var(--primary-900);--d-button-default-icon-color: var(--primary-900);- .container.posts .topic-navigation .btn-toggle-localized-content.--active {- --d-button-default-icon-color: var(--tertiary);- --d-button-default-icon-color--hover: var(--tertiary);- }-.btn-default,.btn-icon-text,.btn-icon,diff --git a/app/serializers/topic_view_serializer.rb b/app/serializers/topic_view_serializer.rbindex 7b1581dac39..a88afe6bd8c 100644--- a/app/serializers/topic_view_serializer.rb+++ b/app/serializers/topic_view_serializer.rb@@ -78,7 +78,6 @@ class TopicViewSerializer < ApplicationSerializer:user_last_posted_at,:is_shared_draft,:slow_mode_enabled_until,- :has_localized_content,:can_localize_topic,:is_nested_view,)@@ -321,17 +320,6 @@ class TopicViewSerializer < ApplicationSerializerobject.topic.visibility_reason_id.present?end- def has_localized_content- topic_has_localization = !object.topic.in_user_locale? && object.topic.has_localization?- return true if topic_has_localization-- object.posts.any? { |post| !post.in_user_locale? && post.has_localization? }- end-- def include_has_localized_content?- SiteSetting.content_localization_enabled- end-def can_localize_topictrueenddiff --git a/config/locales/client.en.yml b/config/locales/client.en.ymlindex 8e45cddadce..e2db672644c 100644--- a/config/locales/client.en.yml+++ b/config/locales/client.en.yml@@ -1795,7 +1795,7 @@ en:enable_smart_lists: "Enable smart lists when writing in the composer"enable_defer: "Enable mark topics as unread"enable_markdown_monospace_font: "Use monospace font in composer's Markdown mode"- show_original_content: "Show original content instead of translated content. Can also be toggled within topics."+ show_original_content: "Show original content instead of translated content."experimental_sidebar:enable: "Enable sidebar"options: "Options"@@ -6314,12 +6314,6 @@ en:default: "%{filter} topics in %{category} without tags"categories: "All categories"- content_localization:- toggle_localized:- translated: "Page is machine-translated. Click to view original."- not_translated: "Page is not translated. Click to translate."- translations_enabled: "Translations enabled"- translations_disabled: "Translations disabled"language_switcher:title: "Change site language"diff --git a/frontend/discourse/app/components/topic-localized-content-toggle.gjs b/frontend/discourse/app/components/topic-localized-content-toggle.gjsdeleted file mode 100644index d714e1827c6..00000000000--- a/frontend/discourse/app/components/topic-localized-content-toggle.gjs+++ /dev/null@@ -1,93 +0,0 @@-import Component from "@glimmer/component";-import { tracked } from "@glimmer/tracking";-import { action } from "@ember/object";-import { service } from "@ember/service";-import { ajax } from "discourse/lib/ajax";-import cookie, { removeCookie } from "discourse/lib/cookie";-import DButton from "discourse/ui-kit/d-button";-import dConcatClass from "discourse/ui-kit/helpers/d-concat-class";-import { i18n } from "discourse-i18n";--const SHOW_ORIGINAL_COOKIE = "content-localization-show-original";-const SHOW_ORIGINAL_COOKIE_EXPIRY = 30;--export default class TopicLocalizedContentToggle extends Component {- @service currentUser;- @service router;- @service toasts;-- @tracked showingOriginal = false;-- constructor() {- super(...arguments);- if (this.currentUser) {- this.showingOriginal =- this.currentUser.user_option?.show_original_content;- } else {- this.showingOriginal = cookie(SHOW_ORIGINAL_COOKIE);- }- }-- @action- async showOriginal() {- const newValue = !this.showingOriginal;-- if (this.currentUser) {- this.currentUser.set("user_option.show_original_content", newValue);- await ajax(`/u/${this.currentUser.username}.json`, {- type: "PUT",- data: { show_original_content: newValue },- });- } else if (newValue) {- cookie(SHOW_ORIGINAL_COOKIE, true, {- path: "/",- expires: SHOW_ORIGINAL_COOKIE_EXPIRY,- });- } else {- removeCookie(SHOW_ORIGINAL_COOKIE, { path: "/" });- }-- const toastKey = this.showingOriginal- ? "content_localization.toggle_localized.translations_enabled"- : "content_localization.toggle_localized.translations_disabled";-- this.showingOriginal = newValue;-- const postStream = this.args.topic?.postStream;- if (postStream) {- const currentURL = this.router.currentURL;- // this is required to clear the post stream cache- // otherwise the old posts before the toggle will be shown- postStream.removeAllPosts();- await this.router.refresh();- // refreshing clears the post number,- // and postStream.refresh nearPost does not load to the correct post- if (this.router.currentURL !== currentURL) {- this.router.replaceWith(currentURL);- }- }-- this.toasts.success({- duration: "short",- data: { message: i18n(toastKey) },- });- }-- get title() {- return this.showingOriginal- ? "content_localization.toggle_localized.not_translated"- : "content_localization.toggle_localized.translated";- }-- <template>- <DButton- @icon="language"- @title={{this.title}}- class={{dConcatClass- "btn btn-default btn-toggle-localized-content no-text"- (unless this.showingOriginal "--active")- }}- @action={{this.showOriginal}}- />- </template>-}diff --git a/frontend/discourse/app/components/topic-timeline/container.gjs b/frontend/discourse/app/components/topic-timeline/container.gjsindex 3fa0edd8169..cc690e9f9e1 100644--- a/frontend/discourse/app/components/topic-timeline/container.gjs+++ b/frontend/discourse/app/components/topic-timeline/container.gjs@@ -9,7 +9,6 @@ import { trustHTML } from "@ember/template";import PluginOutlet from "discourse/components/plugin-outlet";import { actionDescriptionHtml } from "discourse/components/post-action-description";import TopicAdminMenu from "discourse/components/topic-admin-menu";-import TopicLocalizedContentToggle from "discourse/components/topic-localized-content-toggle";import UserTip from "discourse/components/user-tip";import lazyHash from "discourse/helpers/lazy-hash";import topicFeaturedLink from "discourse/helpers/topic-featured-link";@@ -168,10 +167,7 @@ export default class TopicTimelineScrollArea extends Component {}get showTimelineControls() {- return (- !this.args.fullscreen &&- (this.currentUser || this.args.model.has_localized_content)- );+ return !this.args.fullscreen && this.currentUser;}get topicTitle() {@@ -570,10 +566,6 @@ export default class TopicTimelineScrollArea extends Component {@convertToPublicTopic={{@convertToPublicTopic}}@convertToPrivateMessage={{@convertToPrivateMessage}}/>-- {{#if @model.has_localized_content}}- <TopicLocalizedContentToggle @topic={{@model}} />- {{/if}}</div>{{/if}}diff --git a/frontend/discourse/app/templates/topic.gjs b/frontend/discourse/app/templates/topic.gjsindex 31d95ac60c5..5189a869730 100644--- a/frontend/discourse/app/templates/topic.gjs+++ b/frontend/discourse/app/templates/topic.gjs@@ -24,7 +24,6 @@ import SlowModeInfo from "discourse/components/slow-mode-info";import TopicAdminMenu from "discourse/components/topic-admin-menu";import TopicCategory from "discourse/components/topic-category";import TopicFooterButtons from "discourse/components/topic-footer-buttons";-import TopicLocalizedContentToggle from "discourse/components/topic-localized-content-toggle";import TopicMap from "discourse/components/topic-map/index";import TopicMetadata from "discourse/components/topic-metadata";import TopicNavigation from "discourse/components/topic-navigation";@@ -345,9 +344,6 @@ export default <template>@convertToPublicTopic={{@controller.convertToPublicTopic}}@convertToPrivateMessage={{@controller.convertToPrivateMessage}}/>- {{#if @controller.model.has_localized_content}}- <TopicLocalizedContentToggle @topic={{@controller.model}} />- {{/if}}</TopicProgress>{{/if}}diff --git a/frontend/discourse/tests/integration/components/topic-localized-content-toggle-test.gjs b/frontend/discourse/tests/integration/components/topic-localized-content-toggle-test.gjsdeleted file mode 100644index cae4d1d9f9c..00000000000--- a/frontend/discourse/tests/integration/components/topic-localized-content-toggle-test.gjs+++ /dev/null@@ -1,110 +0,0 @@-import { click, render } from "@ember/test-helpers";-import { module, test } from "qunit";-import TopicLocalizedContentToggle from "discourse/components/topic-localized-content-toggle";-import { setupRenderingTest } from "discourse/tests/helpers/component-test";-import pretender, { response } from "discourse/tests/helpers/create-pretender";-import { i18n } from "discourse-i18n";--module(- "Integration | Component | TopicLocalizedContentToggle",- function (hooks) {- setupRenderingTest(hooks, { stubRouter: true });-- hooks.beforeEach(function () {- const router = this.owner.lookup("service:router");- router.currentURL = "/t/1";- router.refresh = async () => {};- router.replaceWith = () => {};- });-- const TOGGLE_SELECTOR = "button.btn-toggle-localized-content";-- test("updates tooltip after toggling from translated to original", async function (assert) {- this.currentUser.user_option.show_original_content = false;-- pretender.put("/u/eviltrout.json", () => response({}));-- const topic = { postStream: { removeAllPosts() {} } };-- await render(- <template><TopicLocalizedContentToggle @topic={{topic}} /></template>- );-- assert- .dom(TOGGLE_SELECTOR)- .hasAttribute(- "title",- i18n("content_localization.toggle_localized.translated"),- "shows translated tooltip when viewing translated content"- );-- assert- .dom(TOGGLE_SELECTOR)- .hasClass(- "--active",- "button is active when showing translated content"- );-- await click(TOGGLE_SELECTOR);-- assert- .dom(TOGGLE_SELECTOR)- .hasAttribute(- "title",- i18n("content_localization.toggle_localized.not_translated"),- "shows not_translated tooltip after toggling to original"- );-- assert- .dom(TOGGLE_SELECTOR)- .doesNotHaveClass(- "--active",- "button is not active when showing original content"- );- });-- test("updates tooltip after toggling from original to translated", async function (assert) {- this.currentUser.user_option.show_original_content = true;-- pretender.put("/u/eviltrout.json", () => response({}));-- const topic = { postStream: { removeAllPosts() {} } };-- await render(- <template><TopicLocalizedContentToggle @topic={{topic}} /></template>- );-- assert- .dom(TOGGLE_SELECTOR)- .hasAttribute(- "title",- i18n("content_localization.toggle_localized.not_translated"),- "shows not_translated tooltip when viewing original content"- );-- assert- .dom(TOGGLE_SELECTOR)- .doesNotHaveClass(- "--active",- "button is not active when showing original content"- );-- await click(TOGGLE_SELECTOR);-- assert- .dom(TOGGLE_SELECTOR)- .hasAttribute(- "title",- i18n("content_localization.toggle_localized.translated"),- "shows translated tooltip after toggling to translated"- );-- assert- .dom(TOGGLE_SELECTOR)- .hasClass(- "--active",- "button is active when showing translated content"- );- });- }-);diff --git a/spec/serializers/topic_view_serializer_spec.rb b/spec/serializers/topic_view_serializer_spec.rbindex e436d313d71..5e136df3db9 100644--- a/spec/serializers/topic_view_serializer_spec.rb+++ b/spec/serializers/topic_view_serializer_spec.rb@@ -715,38 +715,4 @@ RSpec.describe TopicViewSerializer doendendend-- describe "#has_localized_content" do- before { SiteSetting.content_localization_enabled = true }-- it "returns true if the topic has localization" do- Fabricate(:topic_localization, topic:, locale: "ja")- I18n.locale = "ja"- topic.update!(locale: "en")-- json = serialize_topic(topic, user)- expect(json[:has_localized_content]).to eq(true)- end-- it "returns true if any post has localization" do- loc = Fabricate(:post_localization, locale: "ja")- I18n.locale = "ja"- loc.post.update!(locale: "en")-- json = serialize_topic(loc.post.topic, user)- expect(json[:has_localized_content]).to eq(true)- end-- it "returns false if the topic does not have localization" do- json = serialize_topic(topic, user)- expect(json[:has_localized_content]).to eq(false)- end-- it "does not return attribute if setting is disabled" do- SiteSetting.content_localization_enabled = false-- json = serialize_topic(topic, user)- expect(json[:has_localized_content]).to eq(nil)- end- endenddiff --git a/spec/system/content_localization_language_switcher_spec.rb b/spec/system/content_localization_language_switcher_spec.rbindex 000a854ff73..f165f5da037 100644--- a/spec/system/content_localization_language_switcher_spec.rb+++ b/spec/system/content_localization_language_switcher_spec.rb@@ -2,7 +2,6 @@describe "Content localization language switcher" dolet(:switcher_selector) { "button[data-identifier='language-switcher']" }- let(:toggle_localize_button_selector) { "button.btn-toggle-localized-content" }let(:topic_list) { PageObjects::Components::TopicList.new }let(:switcher) { PageObjects::Components::DMenu.new(switcher_selector) }@@ -143,38 +142,6 @@ describe "Content localization language switcher" doendend- it "resets localized content toggle after changing languages" do- SiteSetting.content_localization_language_switcher = "all"-- visit("/t/#{topic.id}")-- language_switcher.select_language("ja")-- expect(topic_list).to have_content("孫子兵法からの人生戦略")- I18n.with_locale(:ja) do- expect(page.find(toggle_localize_button_selector)["title"]).to eq(- I18n.t("js.content_localization.toggle_localized.translated"),- )- end-- page.find(toggle_localize_button_selector).click- expect(topic_list).to have_content("Life strategies from The Art of War")- I18n.with_locale(:ja) do- expect(page.find(toggle_localize_button_selector)["title"]).to eq(- I18n.t("js.content_localization.toggle_localized.not_translated"),- )- end-- language_switcher.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-it "marks the current language as selected in the dropdown" doSiteSetting.content_localization_language_switcher = "all"diff --git a/spec/system/content_localization_spec.rb b/spec/system/content_localization_spec.rbindex 29651d4e776..8fc44bf9752 100644--- a/spec/system/content_localization_spec.rb+++ b/spec/system/content_localization_spec.rb@@ -1,7 +1,6 @@# frozen_string_literal: truedescribe "Content Localization" do- let(:toggle_localize_button_selector) { "button.btn-toggle-localized-content" }let(:switcher_selector) { "button[data-identifier='language-switcher']" }fab!(:japanese_user) { Fabricate(:user, locale: "ja") }@@ -76,47 +75,6 @@ describe "Content Localization" doexpect(topic_page.has_topic_title?("孫子兵法からの人生戦略")).to eq(true)end- it "shows original content when 'Show Original' is selected" do- sign_in(japanese_user)-- visit("/")- topic_list.visit_topic_with_title("孫子兵法からの人生戦略")-- expect(topic_page.has_topic_title?("孫子兵法からの人生戦略")).to eq(true)-- I18n.with_locale(:ja) do- expect(page.find(toggle_localize_button_selector)["title"]).to eq(- I18n.t("js.content_localization.toggle_localized.translated"),- )- end- page.find(toggle_localize_button_selector).click-- expect(topic_page.has_topic_title?("Life strategies from The Art of War")).to eq(true)- I18n.with_locale(:ja) do- expect(page.find(toggle_localize_button_selector)["title"]).to eq(- I18n.t("js.content_localization.toggle_localized.not_translated"),- )- end- visit("/")- topic_list.visit_topic_with_title("Life strategies from The Art of War")- end-- it "persists 'Show Original' preference for logged-in users across page loads" do- sign_in(japanese_user)-- visit("/t/#{topic.id}")- expect(topic_page.has_topic_title?("孫子兵法からの人生戦略")).to eq(true)-- page.find(toggle_localize_button_selector).click- expect(topic_page.has_topic_title?("Life strategies from The Art of War")).to eq(true)-- # preference persists after full page reload- visit("/t/#{topic.id}")- expect(topic_page.has_topic_title?("Life strategies from The Art of War")).to eq(true)-- expect(japanese_user.reload.user_option.show_original_content).to eq(true)- end-it "persists 'Show Original' preference from user preferences interface" dosign_in(japanese_user)@@ -240,31 +198,6 @@ describe "Content Localization" doendend- context "when transitioning from anonymous to logged-in" do- let(:language_switcher) { PageObjects::Components::LanguageSwitcher.new }-- before do- SiteSetting.set_locale_from_cookie = true- SiteSetting.content_localization_language_switcher = "all"- end-- it "ignores the show-original cookie for logged-in users" do- visit("/")- language_switcher.select_language("ja")-- visit("/t/#{topic.id}")- expect(topic_page.has_topic_title?("孫子兵法からの人生戦略")).to eq(true)-- page.find(toggle_localize_button_selector).click- expect(topic_page.has_topic_title?("Life strategies from The Art of War")).to eq(true)-- sign_in(japanese_user)-- visit("/t/#{topic.id}")- expect(topic_page.has_topic_title?("孫子兵法からの人生戦略")).to eq(true)- end- end-context "when editing" dolet(:edit_localized_post_dialog) { PageObjects::Components::Dialog.new }let(:fast_editor) { PageObjects::Components::FastEditor.new }@@ -350,13 +283,6 @@ describe "Content Localization" dotopic_page.click_topic_title_submit_editexpect(topic_page).to have_topic_title(original_translated_title)- # View original - displayed title should update to new original title- page.find(toggle_localize_button_selector).click- expect(topic_page).to have_topic_title("New Original Title")-- # switch back to Japanese to test translation editing- page.find(toggle_localize_button_selector).click-# Viewing translation - Edit translationtopic_page.click_topic_edit_titleexpect(edit_localized_post_dialog).to be_open@@ -445,7 +371,7 @@ describe "Content Localization" dolet(:post_21_obj) { PageObjects::Components::Post.new(21) }- it "respects the show_original toggle for posts loaded dynamically when scrolling (20+ posts)" do+ it "shows original content for a dynamically loaded post via the per-post toggle (20+ posts)" dosign_in(site_local_user)visit("/")@@ -459,16 +385,8 @@ describe "Content Localization" doexpect(page).to have_css("#post_21")expect(topic_page).to have_post_content(post_number: 21, content: "English translation 21")- # toggle should show correct state of post content- page.find(toggle_localize_button_selector).click- scroll_to_post(21)- expect(post_21_obj.post).to have_content("日本語コンテンツ 21")-- # refresh should show correct state of post content- page.refresh- expect(page).to have_css("#site-logo")-- scroll_to_post(21)+ # the per-post toggle shows the original content for the loaded post+ post_21_obj.toggle_localized_contentexpect(post_21_obj.post).to have_content("日本語コンテンツ 21")endend@@ -496,12 +414,6 @@ describe "Content Localization" dotopic_page.visit_topic(shady_topic)expect(page).to have_title(shady_topic_ja_localization.fancy_title)- page.find(toggle_localize_button_selector).click- expect(page).to have_title(shady_topic.title)-- page.find(toggle_localize_button_selector).click- expect(page).to have_title(shady_topic_ja_localization.fancy_title)-SiteSetting.content_localization_enabled = falsepage.refreshdiff --git a/spec/system/page_objects/components/post.rb b/spec/system/page_objects/components/post.rbindex 8d603c69bcd..5b5e177b5e2 100644--- a/spec/system/page_objects/components/post.rb+++ b/spec/system/page_objects/components/post.rb@@ -75,6 +75,11 @@ module PageObjectsfind(".post-language-content")end+ def toggle_localized_content+ post.find(".post-info.post-language .fk-d-tooltip__trigger").click+ self+ end+def open_post_historypost.find(".post-info.edits").clickend