mirror of
https://ghfast.top/https://github.com/discourse/discourse-translator.git
synced 2026-07-16 11:46:33 +08:00
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.
46 lines
1.2 KiB
Text
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>
|
|
}
|