discourse-translator/assets/javascripts/discourse/components/show-original-content.gjs
Natalie Tay 353734504b
FEATURE: Show full topic translations (#205)
This feature shows a fully translated topic in the user's language. For now, the topic needs to already have translations for the translated topic to show. If there are posts that have not been translated, the original content will be shown.

The `translated_title` is returned via the `TopicViewSerializer` and displayed via the `applyTransformations` API.
The `translated_cooked` is returned via the `PostSerializer` and displayed via `decorateCooked`.

This takes a different approach from the previous PR https://github.com/discourse/discourse-translator/pull/199 which overrode the `fancy_title` and `cooked` directly.
2025-02-11 14:08:10 +08:00

46 lines
1.2 KiB
Text

import Component from "@glimmer/component";
import { tracked } from "@glimmer/tracking";
import { action } from "@ember/object";
import { service } from "@ember/service";
import DButton from "discourse/components/d-button";
import concatClass from "discourse/helpers/concat-class";
export default class ShowOriginalContent extends Component {
@service router;
@tracked isTranslated = true;
constructor() {
super(...arguments);
this.isTranslated = !new URLSearchParams(window.location.search).has(
"show"
);
}
@action
async showOriginal() {
const params = new URLSearchParams(window.location.search);
if (this.isTranslated) {
params.append("show", "original");
} else {
params.delete("show");
}
window.location.search = params.toString();
}
get title() {
return this.isTranslated
? "translator.content_translated"
: "translator.content_not_translated";
}
<template>
<div class="discourse-translator_toggle-original">
<DButton
@icon="language"
@title={{this.title}}
class={{concatClass "btn btn-default" (if this.isTranslated "active")}}
@action={{this.showOriginal}}
/>
</div>
</template>
}