added translation revert

This commit is contained in:
Nicolas Constant 2023-08-05 18:32:23 -04:00
parent 38b052f06b
commit 73ac37a8f4
No known key found for this signature in database
GPG Key ID: 1E9F677FB01A5688
3 changed files with 46 additions and 5 deletions

View File

@ -1,6 +1,6 @@
<div class="translation" *ngIf="isTranslationAvailable">
<div class="translation" *ngIf="isTranslationAvailable && showTranslationButton">
<a href class="translation__link" (click)="translate()">Translate</a>
</div>
<div class="translation" *ngIf="translatedBy">
<span class="translation__by">Translated by {{translatedBy}}</span>
<div class="translation translation__display" *ngIf="isTranslationAvailable && !showTranslationButton">
<span class="translation__by">Translated by {{translatedBy}}</span> <a href (click)="revertTranslation()" class="translation__display__link">revert</a>
</div>

View File

@ -24,4 +24,21 @@
text-align: left;
padding: 5px 0 0 0;
}
&__display {
display: flex;
justify-content: space-between;
&__link {
padding: 5px 0 0 0;
font-size: 12px;
color: #656b8f;
transition: all .2s;
&:hover {
text-decoration: none;
color: #9fa5ca;
}
}
}
}

View File

@ -19,11 +19,13 @@ export class StatusTranslateComponent implements OnInit, OnDestroy {
private languageSub: Subscription;
private languagesSub: Subscription;
private loadedTranslation: Translation;
selectedLanguage: ILanguage;
configuredLanguages: ILanguage[] = [];
isTranslationAvailable: boolean;
showTranslationButton: boolean = true;
translatedBy: string;
@Input() status: StatusWrapper;
@ -79,11 +81,18 @@ export class StatusTranslateComponent implements OnInit, OnDestroy {
}
translate(): boolean {
if(this.loadedTranslation){
this.translation.next(this.loadedTranslation);
this.showTranslationButton = false;
return false;
}
this.mastodonWrapperService.translate(this.status.provider, this.status.status.id, this.selectedLanguage.iso639)
.then(x => {
.then(x => {
this.loadedTranslation = x;
this.translation.next(x);
this.translatedBy = x.provider;
this.isTranslationAvailable = false;
this.showTranslationButton = false;
})
.catch((err: HttpErrorResponse) => {
console.error(err);
@ -91,4 +100,19 @@ export class StatusTranslateComponent implements OnInit, OnDestroy {
});
return false;
}
revertTranslation(): boolean {
let revertTranslate: Translation;
revertTranslate = {
content: this.status.status.content,
language: this.loadedTranslation.detected_source_language,
detected_source_language: this.loadedTranslation.language,
provider: this.loadedTranslation.provider,
spoiler_text: this.status.status.spoiler_text
};
this.translation.next(revertTranslate);
this.showTranslationButton = true;
return false;
}
}