Skip to content

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

UX: Improvements to translation editor (#35805)

Keegan Georgecc626cd83f23
diff --git a/app/assets/stylesheets/common/d-editor.scss b/app/assets/stylesheets/common/d-editor.scss
index db35f67978c..46d25c320ce 100644
--- a/app/assets/stylesheets/common/d-editor.scss
+++ b/app/assets/stylesheets/common/d-editor.scss
@@ -422,10 +422,23 @@
.topic-title-translator {
display: flex;
align-items: center;
- gap: 2rem;
+ width: 100%;
+
+ .title-input-column {
+ display: flex;
+ flex: 1;
+ align-items: center;
+ gap: 2rem;
- input {
- width: 48.5vw;
+ input {
+ flex: 1;
+ min-width: 0;
+ }
+ }
+
+ .title-preview-spacer {
+ flex: 1;
+ margin-left: 9px;
}
}
@@ -442,23 +455,8 @@
box-sizing: border-box;
border: var(--d-input-border);
border-radius: var(--d-border-radius);
- padding: var(--translation-preview-padding);
position: relative;
- padding-top: calc(var(--translation-preview-padding) * 2);
-
- &__header {
- position: absolute;
- display: inline-flex;
- align-items: center;
- height: 1.5rem;
- top: 0;
- left: 0;
- background: var(--primary-very-low);
- padding: 0.45rem var(--translation-preview-padding);
- border-radius: var(--d-border-radius);
- font-size: var(--font-down-1-rem);
- color: var(--primary-high);
- }
+ overflow: auto;
&__original-locale {
margin-left: 0.5rem;
@@ -469,4 +467,72 @@
border-radius: var(--d-border-radius);
}
}
+
+ .d-editor-translation-preview-header {
+ position: sticky;
+ top: 0;
+ z-index: z("base");
+ display: flex;
+ justify-content: space-between;
+ align-items: center;
+ padding: 0.5rem var(--translation-preview-padding, 1rem);
+ padding-bottom: 0.25rem;
+ border-bottom: 1px solid var(--primary-low);
+ background: var(--primary-very-low);
+ border-radius: var(--d-border-radius) var(--d-border-radius) 0 0;
+
+ &__title {
+ display: inline-flex;
+ align-items: center;
+ font-size: var(--font-down-1-rem);
+ color: var(--primary-high);
+ font-weight: 500;
+ }
+
+ &__controls {
+ display: flex;
+ gap: 0.5em;
+
+ .btn {
+ position: relative;
+ padding: 0.65em 0.75em;
+ font-size: var(--font-down-1-rem);
+ color: var(--d-nav-color);
+ background-color: var(--d-nav-bg-color);
+ transition: var(--d-button-transition);
+ border-radius: var(--d-nav-pill-border-radius);
+
+ &:hover:not(.active) {
+ color: var(--d-nav-color--hover);
+ background: var(--d-nav-bg-color--hover);
+ }
+
+ &.active {
+ color: var(--d-nav-color--active);
+ background: var(--d-nav-bg-color--active);
+
+ &::after {
+ content: "";
+ position: absolute;
+ left: 0;
+ bottom: calc(-0.25rem - 2px);
+ right: 0;
+ height: var(--d-nav-underline-height);
+ background: var(--d-nav-color--active);
+ }
+ }
+ }
+ }
+ }
+
+ .d-editor-translation-preview-content {
+ padding-inline: var(--translation-preview-padding, 1rem);
+ }
+
+ .d-editor-translation-preview-empty {
+ color: var(--primary-medium);
+ font-style: italic;
+ padding: 2rem 0;
+ text-align: center;
+ }
}
diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml
index c4f044d0f5a..3bf26f7c20e 100644
--- a/config/locales/client.en.yml
+++ b/config/locales/client.en.yml
@@ -2933,6 +2933,10 @@ en:
select: "Select translation"
save: "Save translation"
original_content: "Original post content"
+ translation_preview: "Translation preview"
+ original: "Original"
+ translation: "Translation"
+ no_translation_yet: "Start typing to see translation preview..."
placeholder: "Enter translation for post here..."
group_mentioned_limit:
diff --git a/frontend/discourse/app/components/d-editor-original-translation-preview.gjs b/frontend/discourse/app/components/d-editor-original-translation-preview.gjs
index 26b88e4449d..2870922a2f4 100644
--- a/frontend/discourse/app/components/d-editor-original-translation-preview.gjs
+++ b/frontend/discourse/app/components/d-editor-original-translation-preview.gjs
@@ -1,27 +1,79 @@
import Component from "@glimmer/component";
+import { tracked } from "@glimmer/tracking";
+import { fn } from "@ember/helper";
+import { on } from "@ember/modifier";
+import { action } from "@ember/object";
import { htmlSafe } from "@ember/template";
import CookText from "discourse/components/cook-text";
import { i18n } from "discourse-i18n";
export default class DEditorOriginalTranslationPreview extends Component {
+ @tracked showOriginal = true;
+
get originalLocale() {
return this.args.model.postLocale;
}
+ get translationText() {
+ return typeof this.args.model.translationText === "function"
+ ? this.args.model.translationText()
+ : this.args.model.translationText;
+ }
+
+ @action
+ setView(view) {
+ this.showOriginal = view === "original";
+ }
+
<template>
<div class="d-editor-translation-preview-wrapper">
- <span class="d-editor-translation-preview-wrapper__header">
- {{i18n "composer.translations.original_content"}}
- <span class="d-editor-translation-preview-wrapper__original-locale">
- {{this.originalLocale}}
+ <div class="d-editor-translation-preview-header">
+ <span class="d-editor-translation-preview-header__title">
+ {{#if this.showOriginal}}
+ {{i18n "composer.translations.original_content"}}
+ <span class="d-editor-translation-preview-wrapper__original-locale">
+ {{this.originalLocale}}
+ </span>
+ {{else}}
+ {{i18n "composer.translations.translation_preview"}}
+ {{/if}}
</span>
- </span>
- {{#if @model.cookedPost}}
- {{htmlSafe @model.cookedPost}}
- {{else if @model.rawPost}}
- <CookText @rawText={{@model.rawPost}} />
- {{/if}}
+ <div class="d-editor-translation-preview-header__controls">
+ <button
+ type="button"
+ class="btn btn-flat btn-small {{if this.showOriginal 'active'}}"
+ {{on "click" (fn this.setView "original")}}
+ >
+ {{i18n "composer.translations.original"}}
+ </button>
+ <button
+ type="button"
+ class="btn btn-flat btn-small {{unless this.showOriginal 'active'}}"
+ {{on "click" (fn this.setView "translation")}}
+ >
+ {{i18n "composer.translations.translation"}}
+ </button>
+ </div>
+ </div>
+
+ <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}}
+ {{else}}
+ {{#if this.translationText}}
+ <CookText @rawText={{this.translationText}} />
+ {{else}}
+ <div class="d-editor-translation-preview-empty">
+ {{i18n "composer.translations.no_translation_yet"}}
+ </div>
+ {{/if}}
+ {{/if}}
+ </div>
</div>
</template>
}
diff --git a/frontend/discourse/app/components/modal/post-translations.gjs b/frontend/discourse/app/components/modal/post-translations.gjs
index cc4b01faa50..22e24dd714a 100644
--- a/frontend/discourse/app/components/modal/post-translations.gjs
+++ b/frontend/discourse/app/components/modal/post-translations.gjs
@@ -68,6 +68,7 @@ export default class PostTranslationsModal extends Component {
model: {
postLocale: originalLocale,
rawPost: raw,
+ translationText: () => this.composer.model?.reply,
},
},
post: this.args.model.post,
diff --git a/frontend/discourse/app/components/post-translation-editor.gjs b/frontend/discourse/app/components/post-translation-editor.gjs
index 87fbaba2e0a..75578c78cc7 100644
--- a/frontend/discourse/app/components/post-translation-editor.gjs
+++ b/frontend/discourse/app/components/post-translation-editor.gjs
@@ -112,14 +112,17 @@ export default class PostTranslationEditor extends Component {
{{#if this.composer.model.post.firstPost}}
<div class="topic-title-translator title-and-category with-preview">
- <TextField
- @value={{this.composer.model.title}}
- @id="translated-topic-title"
- @maxLength={{this.siteSettings.max_topic_title_length}}
- @placeholder={{this.composer.model.topic.title}}
- @disabled={{this.composer.loading}}
- @autocomplete="off"
- />
+ <div class="title-input-column">
+ <TextField
+ @value={{this.composer.model.title}}
+ @id="translated-topic-title"
+ @maxLength={{this.siteSettings.max_topic_title_length}}
+ @placeholder={{this.composer.model.topic.title}}
+ @disabled={{this.composer.loading}}
+ @autocomplete="off"
+ />
+ </div>
+ <div class="title-preview-spacer"></div>
</div>
{{/if}}
diff --git a/frontend/discourse/app/components/post/menu/buttons/add-translation.gjs b/frontend/discourse/app/components/post/menu/buttons/add-translation.gjs
index 1051e660c9d..8fc7669e4aa 100644
--- a/frontend/discourse/app/components/post/menu/buttons/add-translation.gjs
+++ b/frontend/discourse/app/components/post/menu/buttons/add-translation.gjs
@@ -71,6 +71,7 @@ export default class PostMenuAddTranslationButton extends Component {
model: {
postLocale: this.args.post.locale,
rawPost: raw,
+ translationText: () => this.composer.model?.reply,
},
},
post: this.args.post,
diff --git a/frontend/discourse/app/controllers/topic.js b/frontend/discourse/app/controllers/topic.js
index 2ba48ef7dde..d5eedc8fc42 100644
--- a/frontend/discourse/app/controllers/topic.js
+++ b/frontend/discourse/app/controllers/topic.js
@@ -970,7 +970,11 @@ export default class TopicController extends Controller {
warningsDisabled: true,
hijackPreview: {
component: DEditorOriginalTranslationPreview,
- model: { postLocale: post.locale, rawPost: raw },
+ model: {
+ postLocale: post.locale,
+ rawPost: raw,
+ translationText: () => this.composer.model?.reply,
+ },
},
post,
selectedTranslationLocale: this.currentUser?.effective_locale,