Skip to content

Commit fac9224

Browse files
committed
Show toggle
1 parent 1c003d8 commit fac9224

File tree

4 files changed

+57
-2
lines changed

4 files changed

+57
-2
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import Component from "@glimmer/component";
2+
import { service } from "@ember/service";
3+
import { action } from "@ember/object";
4+
import DButton from "discourse/components/d-button";
5+
import concatClass from "discourse/helpers/concat-class";
6+
import { tracked } from "@glimmer/tracking";
7+
8+
export default class ShowOriginalContent extends Component {
9+
@service router;
10+
@tracked active = true;
11+
12+
constructor() {
13+
super(...arguments);
14+
this.active = !new URLSearchParams(window.location.search).has("show_original");
15+
}
16+
17+
@action
18+
async showOriginal() {
19+
this.active = !this.active;
20+
window.location.search = this.active ? "" : `show_original=1`;
21+
}
22+
23+
get title() {
24+
return this.active
25+
? "translator.hide_translation"
26+
: "translator.show_translation";
27+
}
28+
29+
<template>
30+
<div class="discourse-translator_toggle-original">
31+
<DButton
32+
@icon="language"
33+
@title={{this.title}}
34+
class={{concatClass "btn btn-default" (if this.active "active")}}
35+
@action={{this.showOriginal}}
36+
>
37+
</DButton>
38+
</div>
39+
</template>
40+
}

assets/javascripts/discourse/initializers/extend-for-translate-button.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { i18n } from "discourse-i18n";
66
import LanguageSwitcher from "../components/language-switcher";
77
import ToggleTranslationButton from "../components/post-menu/toggle-translation-button";
88
import TranslatedPost from "../components/translated-post";
9+
import ShowOriginalContent from "../components/show-original-content";
910

1011
function initializeTranslation(api) {
1112
const siteSettings = api.container.lookup("service:site-settings");
@@ -23,7 +24,9 @@ function initializeTranslation(api) {
2324
);
2425
}
2526

26-
if (currentUser) {
27+
if (siteSettings.experimental_topic_translation) {
28+
api.renderInOutlet("timeline-controls-before", ShowOriginalContent);
29+
} else {
2730
customizePostMenu(api);
2831
}
2932
}

assets/stylesheets/common/common.scss

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,15 @@
22
.fk-d-menu__inner-content {
33
max-height: 50vh;
44
}
5+
6+
.timeline-controls {
7+
display: flex;
8+
9+
.discourse-translator_toggle-original {
10+
margin-right: 0.5em;
11+
12+
button.active svg {
13+
color: var(--tertiary);
14+
}
15+
}
16+
}

plugin.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ module ::DiscourseTranslator
5555

5656
add_to_serializer :post, :cooked, false do
5757
return super() if !SiteSetting.experimental_topic_translation
58-
return super() if scope.request.params["show-original"].present?
58+
return super() if scope.request.params["show_original"].present?
5959
return super() if !object.has_translation?(I18n.locale)
6060
translated = object.custom_fields[::DiscourseTranslator::TRANSLATED_CUSTOM_FIELD]
6161
translated[I18n.locale]

0 commit comments

Comments
 (0)