7 Commits

6 changed files with 35 additions and 6 deletions

BIN
bun.lockb Executable file

Binary file not shown.

View File

@@ -13,7 +13,6 @@ export class NWUITextAreaComponent implements AfterViewInit {
@Input() disabled = false;
@Input() value = '';
@Input() contenteditable = true;
// eslint-disable-next-line @typescript-eslint/no-empty-function
@Output() leave = new EventEmitter<string>();
@ViewChild('ref') ref: ElementRef<HTMLDivElement> | null = null;

View File

@@ -1,6 +1,6 @@
{
"name": "@nitro-plus-translator/source",
"version": "0.0.0",
"version": "0.0.1",
"license": "MIT",
"scripts": {
"start": "nx serve",
@@ -54,7 +54,8 @@
"prettier": "^2.6.2",
"ts-jest": "^29.1.0",
"ts-node": "10.9.1",
"typescript": "~5.4.2"
"typescript": "~5.4.2",
"bun-types": "latest"
},
"nx": {
"includedScripts": []

View File

@@ -6,5 +6,8 @@
<nwui-button (click)="onClearClicked()">
<span><i class="lni lni-trash-can"></i> Clear</span>
</nwui-button>
<nwui-button (click)="onSaveClicked()">
<span><i class="lni lni-save"></i> Save</span>
</nwui-button>
</div>
<app-text-list [elements]="elements"></app-text-list>

View File

@@ -62,4 +62,27 @@ export class AppComponent implements OnInit {
this.elements = [];
localStorage.removeItem(LocalStorageKeys.TRANSLATIONS);
}
onSaveClicked() {
const original_file: NpsFile = JSON.parse(
localStorage.getItem(LocalStorageKeys.ORIGINAL_FILE) ?? '{"file_name":"", "original_text":""}',
);
if (original_file.file_name && original_file.original_text) {
const data: TranslateData[] = JSON.parse(localStorage.getItem(LocalStorageKeys.TRANSLATIONS) ?? '[]');
if (!data.length) {
alert('No data');
return;
}
original_file.translated_text = original_file.original_text;
data.forEach((el) => {
original_file.translated_text = original_file.translated_text?.replace(el.english_text, el.translated_text);
});
const element = document.createElement('a');
const file = new Blob([original_file.translated_text], { type: 'text/plain' });
element.href = URL.createObjectURL(file);
element.download = original_file.file_name;
element.click();
}
}
}

View File

@@ -1,7 +1,7 @@
import { CommonModule } from '@angular/common';
import { Component, ElementRef, Input, OnInit, ViewChild } from '@angular/core';
import { Component, Input, OnInit, ViewChild } from '@angular/core';
import { NWUIButtonComponent, NWUITextAreaComponent } from '@nwaifu-ui';
import { LocalStorageKeys } from 'src/app/consts';
import { LocalStorageKeys } from '../../consts';
import { TranslateData } from '../../dto/translate_data.dto';
import { ETranslateService } from '../../services/translate.enums';
import { TranslateService } from '../../services/translate.service';
@@ -15,7 +15,7 @@ import { TranslateService } from '../../services/translate.service';
providers: [TranslateService],
})
export class TranslateBlockComponent implements OnInit {
@ViewChild('translatedText') translatedText: ElementRef<HTMLDivElement> | null = null;
@ViewChild('translatedText') translatedText: NWUITextAreaComponent | null = null;
@Input({ required: true }) item: TranslateData = { english_text: '', translated_text: '' };
@Input({ required: true }) index = 0;
translateLoading = false;
@@ -40,6 +40,7 @@ export class TranslateBlockComponent implements OnInit {
private sendToTranslate(service: ETranslateService = ETranslateService.GOOGLE) {
this.translateLoading = true;
this.translateService.translate(this.item.english_text, service).subscribe((text) => {
if (this.translatedText) if (this.translatedText.ref) this.translatedText.ref.nativeElement.textContent = text;
this.item.translated_text = text;
this.isEditing = false;
this.translateLoading = false;
@@ -61,12 +62,14 @@ export class TranslateBlockComponent implements OnInit {
saveTranslate(text: string) {
this.isEditing = false;
if (this.translatedText) if (this.translatedText.ref) this.translatedText.ref.nativeElement.textContent = '';
this.item.translated_text = text;
this.saveChanges();
}
clear() {
this.item.translated_text = '';
this.isEditing = true;
if (this.translatedText) if (this.translatedText.ref) this.translatedText.ref.nativeElement.textContent = '';
this.saveChanges();
}
}