A platform for community discussion. Free, open, simple.
DEV: Ability to view raw OP in translation editor (#35848)
Keegan George6adb4f8e845f
diff --git a/app/assets/stylesheets/common/d-editor.scss b/app/assets/stylesheets/common/d-editor.scssindex 46d25c320ce..61c9787ed44 100644--- a/app/assets/stylesheets/common/d-editor.scss+++ b/app/assets/stylesheets/common/d-editor.scss@@ -523,10 +523,22 @@}}}++ &__raw-toggle {+ padding-left: 0.5rem;+ margin-left: 0.5rem;+ border-left: 1px solid var(--primary-low);+ }}.d-editor-translation-preview-content {padding-inline: var(--translation-preview-padding, 1rem);+ overflow: hidden;++ img:not(.thumbnail, .ytp-thumbnail-image, .emoji) {+ max-width: 100%;+ height: auto;+ }}.d-editor-translation-preview-empty {@@ -535,4 +547,12 @@padding: 2rem 0;text-align: center;}++ .d-editor-translation-preview-raw {+ font-family: var(--d-font-family--monospace);+ font-size: var(--font-down-1);+ white-space: pre-wrap;+ word-wrap: break-word;+ overflow-x: auto;+ }}diff --git a/config/locales/client.en.yml b/config/locales/client.en.ymlindex 7e8894606bb..58b4a3fa49c 100644--- a/config/locales/client.en.yml+++ b/config/locales/client.en.yml@@ -2940,12 +2940,13 @@ en:title: "Translating post"select: "Select translation"save: "Save translation"- original_content: "Original post content"+ original_content: "Original post"translation_preview: "Translation preview"original: "Original"translation: "Translation"no_translation_yet: "Start typing to see translation preview..."placeholder: "Enter translation for post here..."+ show_raw_markdown: "Show raw"group_mentioned_limit:one: "<b>Warning!</b> You mentioned <a href='%{group_link}'>%{group}</a>, however this group has more members than the administrator configured mention limit of %{count} user. Nobody will be notified."diff --git a/frontend/discourse/app/components/d-editor-original-translation-preview.gjs b/frontend/discourse/app/components/d-editor-original-translation-preview.gjsindex 2870922a2f4..cb099d8b24c 100644--- a/frontend/discourse/app/components/d-editor-original-translation-preview.gjs+++ b/frontend/discourse/app/components/d-editor-original-translation-preview.gjs@@ -5,10 +5,12 @@ import { on } from "@ember/modifier";import { action } from "@ember/object";import { htmlSafe } from "@ember/template";import CookText from "discourse/components/cook-text";+import DToggleSwitch from "discourse/components/d-toggle-switch";import { i18n } from "discourse-i18n";export default class DEditorOriginalTranslationPreview extends Component {@tracked showOriginal = true;+ @tracked showRawMarkdown = false;get originalLocale() {return this.args.model.postLocale;@@ -23,6 +25,12 @@ export default class DEditorOriginalTranslationPreview extends Component {@actionsetView(view) {this.showOriginal = view === "original";+ this.showRawMarkdown = false;+ }++ @action+ toggleRawMarkdown() {+ this.showRawMarkdown = !this.showRawMarkdown;}<template>@@ -34,6 +42,13 @@ export default class DEditorOriginalTranslationPreview extends Component {<span class="d-editor-translation-preview-wrapper__original-locale">{{this.originalLocale}}</span>+ <div class="d-editor-translation-preview-header__raw-toggle">+ <DToggleSwitch+ @state={{this.showRawMarkdown}}+ @label="composer.translations.show_raw_markdown"+ {{on "click" this.toggleRawMarkdown}}+ />+ </div>{{else}}{{i18n "composer.translations.translation_preview"}}{{/if}}@@ -59,10 +74,18 @@ export default class DEditorOriginalTranslationPreview extends Component {<div class="d-editor-translation-preview-content">{{#if this.showOriginal}}- {{#if @model.cookedPost}}- {{htmlSafe @model.cookedPost}}- {{else if @model.rawPost}}- <CookText @rawText={{@model.rawPost}} />+ {{#if this.showRawMarkdown}}+ {{#if @model.rawPost}}+ <pre+ class="d-editor-translation-preview-raw"+ >{{@model.rawPost}}</pre>+ {{/if}}+ {{else}}+ {{#if @model.cookedPost}}+ {{htmlSafe @model.cookedPost}}+ {{else if @model.rawPost}}+ <CookText @rawText={{@model.rawPost}} />+ {{/if}}{{/if}}{{else}}{{#if this.translationText}}diff --git a/spec/system/page_objects/components/d_editor_original_translation_preview.rb b/spec/system/page_objects/components/d_editor_original_translation_preview.rbnew file mode 100644index 00000000000..5b26d800ccf--- /dev/null+++ b/spec/system/page_objects/components/d_editor_original_translation_preview.rb@@ -0,0 +1,60 @@+# frozen_string_literal: true++module PageObjects+ module Components+ class DEditorOriginalTranslationPreview < PageObjects::Components::Base+ PREVIEW_SELECTOR = ".d-editor-translation-preview-wrapper"+ RAW_TOGGLE_SELECTOR = ".d-editor-translation-preview-header__raw-toggle"+ RAW_CONTENT_SELECTOR = "pre.d-editor-translation-preview-raw"+ RENDERED_CONTENT_SELECTOR = ".d-editor-translation-preview-content"++ def has_raw_toggle?+ page.has_css?(RAW_TOGGLE_SELECTOR)+ end++ def has_no_raw_toggle?+ page.has_no_css?(RAW_TOGGLE_SELECTOR)+ end++ def raw_toggle+ PageObjects::Components::DToggleSwitch.new(+ "#{RAW_TOGGLE_SELECTOR} .d-toggle-switch__checkbox",+ )+ end++ def click_original_tab+ find("button", text: I18n.t("js.composer.translations.original")).click+ self+ end++ def click_translation_tab+ find("button", text: I18n.t("js.composer.translations.translation")).click+ self+ end++ def original_tab_active?+ page.has_css?("button.active", text: I18n.t("js.composer.translations.original"))+ end++ def translation_tab_active?+ page.has_css?("button.active", text: I18n.t("js.composer.translations.translation"))+ end++ def has_raw_markdown_content?+ page.has_css?(RAW_CONTENT_SELECTOR)+ end++ def has_no_raw_markdown_content?+ page.has_no_css?(RAW_CONTENT_SELECTOR)+ end++ def raw_markdown_content+ find(RAW_CONTENT_SELECTOR).text+ end++ def has_rendered_content?+ page.has_css?(RENDERED_CONTENT_SELECTOR) && page.has_no_css?(RAW_CONTENT_SELECTOR)+ end+ end+ end+enddiff --git a/spec/system/post_translation_spec.rb b/spec/system/post_translation_spec.rbindex b01b4da1252..18a2914c6ca 100644--- a/spec/system/post_translation_spec.rb+++ b/spec/system/post_translation_spec.rb@@ -165,4 +165,88 @@ describe "Post translations", type: :system doexpect(page.has_no_css?("#{POST_LANGUAGE_SWITCHER_SELECTOR} .d-button-label")).to be trueendend++ context "when viewing raw markdown in translation editor" do+ fab!(:markdown_post) do+ Fabricate(+ :post,+ topic: topic,+ raw: "# Heading\n\n**Bold** text with [link](https://example.com) and *italic*",+ )+ end+ let(:translation_preview) { PageObjects::Components::DEditorOriginalTranslationPreview.new }++ it "shows raw markdown toggle only on Original tab" do+ topic_page.visit_topic(topic)+ find("#post_#{markdown_post.post_number} .post-action-menu-edit-translations-trigger").click+ find(".update-translations-menu__add .post-action-menu__add-translation").click++ expect(composer).to be_opened+ expect(translation_preview).to have_raw_toggle+ expect(translation_preview.original_tab_active?).to be true++ translation_preview.click_translation_tab+ expect(translation_preview.translation_tab_active?).to be true+ expect(translation_preview).to have_no_raw_toggle+ end++ it "displays rendered HTML by default" do+ topic_page.visit_topic(topic)+ find("#post_#{markdown_post.post_number} .post-action-menu-edit-translations-trigger").click+ find(".update-translations-menu__add .post-action-menu__add-translation").click++ expect(composer).to be_opened+ expect(translation_preview.original_tab_active?).to be true+ expect(translation_preview).to have_rendered_content+ expect(translation_preview).to have_no_raw_markdown_content+ end++ it "displays raw markdown when toggle is enabled" do+ topic_page.visit_topic(topic)+ find("#post_#{markdown_post.post_number} .post-action-menu-edit-translations-trigger").click+ find(".update-translations-menu__add .post-action-menu__add-translation").click++ expect(composer).to be_opened+ translation_preview.raw_toggle.toggle++ expect(translation_preview).to have_raw_markdown_content+ raw_content = translation_preview.raw_markdown_content+ expect(raw_content).to include("# Heading")+ expect(raw_content).to include("**Bold**")+ expect(raw_content).to include("[link](https://example.com)")+ expect(raw_content).to include("*italic*")+ end++ it "resets raw markdown view when switching tabs" do+ topic_page.visit_topic(topic)+ find("#post_#{markdown_post.post_number} .post-action-menu-edit-translations-trigger").click+ find(".update-translations-menu__add .post-action-menu__add-translation").click++ expect(composer).to be_opened+ translation_preview.raw_toggle.toggle+ expect(translation_preview).to have_raw_markdown_content++ translation_preview.click_translation_tab+ expect(translation_preview).to have_no_raw_toggle++ translation_preview.click_original_tab+ expect(translation_preview).to have_raw_toggle+ expect(translation_preview.raw_toggle).to be_unchecked+ expect(translation_preview).to have_rendered_content+ end++ it "maintains raw markdown state while on Original tab" do+ topic_page.visit_topic(topic)+ find("#post_#{markdown_post.post_number} .post-action-menu-edit-translations-trigger").click+ find(".update-translations-menu__add .post-action-menu__add-translation").click++ expect(composer).to be_opened+ translation_preview.raw_toggle.toggle+ expect(translation_preview).to have_raw_markdown_content++ translation_preview.raw_toggle.toggle+ expect(translation_preview).to have_no_raw_markdown_content+ expect(translation_preview).to have_rendered_content+ end+ endend