File tree Expand file tree Collapse file tree 4 files changed +57
-2
lines changed Expand file tree Collapse file tree 4 files changed +57
-2
lines changed Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ import { i18n } from "discourse-i18n";
66import LanguageSwitcher from "../components/language-switcher" ;
77import ToggleTranslationButton from "../components/post-menu/toggle-translation-button" ;
88import TranslatedPost from "../components/translated-post" ;
9+ import ShowOriginalContent from "../components/show-original-content" ;
910
1011function 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}
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff 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 ]
You can’t perform that action at this time.
0 commit comments