3 Commits

Author SHA1 Message Date
53fee00315 New version: v0.2.2 2024-06-27 15:01:50 +03:00
c508caab7b Merge branch 'feature/i18n-translator' into dev 2024-06-27 14:52:16 +03:00
e90a1bb6ec feat: i18n for translator 2024-06-27 14:51:38 +03:00
10 changed files with 81 additions and 37 deletions

View File

@@ -1,6 +1,6 @@
@if (elements_data.length) { @if (elements_data.length) {
<h1>Всего: {{ elements_data.length }}</h1> <h1>{{ "ROW_COUNT_LABEL" | translate }}: {{ elements_data.length }}</h1>
<h2>Файл: {{ fileName }}</h2> <h2>{{ "FILE_NAME_LABEL" | translate }}: {{ fileName }}</h2>
} }
<div id="elements"> <div id="elements">
@for (item of elements_data; track $index) { @for (item of elements_data; track $index) {

View File

@@ -1,5 +1,6 @@
import { CommonModule } from "@angular/common"; import { CommonModule } from "@angular/common";
import { Component, Input, OnInit, QueryList, ViewChildren } from "@angular/core"; import { Component, Input, OnInit, QueryList, ViewChildren } from "@angular/core";
import { TranslationPipe } from "../../../../pipes/translation.pipe";
import { NpsFile, TranslateData } from "../../dto/translate_data.dto"; import { NpsFile, TranslateData } from "../../dto/translate_data.dto";
import { TranslateBlockComponent } from "../translate_block/translate_block.component"; import { TranslateBlockComponent } from "../translate_block/translate_block.component";
@@ -8,7 +9,7 @@ import { TranslateBlockComponent } from "../translate_block/translate_block.comp
templateUrl: "./text_list.component.html", templateUrl: "./text_list.component.html",
styleUrls: ["./text_list.component.scss"], styleUrls: ["./text_list.component.scss"],
standalone: true, standalone: true,
imports: [CommonModule, TranslateBlockComponent], imports: [CommonModule, TranslateBlockComponent, TranslationPipe],
}) })
export class TextListComponent implements OnInit { export class TextListComponent implements OnInit {
@ViewChildren("translateBlock") translate_blocks: QueryList<TranslateBlockComponent> | null = @ViewChildren("translateBlock") translate_blocks: QueryList<TranslateBlockComponent> | null =

View File

@@ -11,8 +11,14 @@
> >
</div> </div>
<div class="btns"> <div class="btns">
<nwui-button (click)="sendToGoogleTranslate()" [disabled]="translateLoading">Translate</nwui-button> <nwui-button (click)="sendToGoogleTranslate()" [disabled]="translateLoading">{{
<nwui-button (click)="isEditing = !isEditing" [disabled]="isEditing">Edit</nwui-button> "TRANSLATE_BTN" | translate
<nwui-button (click)="clear()" [disabled]="!item.translated_text.length">Clear</nwui-button> }}</nwui-button>
<nwui-button (click)="isEditing = !isEditing" [disabled]="isEditing">{{
"EDIT_BTN" | translate
}}</nwui-button>
<nwui-button (click)="clear()" [disabled]="!item.translated_text.length">{{
"CLEAR_ROW_BTN" | translate
}}</nwui-button>
</div> </div>
</div> </div>

View File

@@ -1,38 +1,41 @@
import { CommonModule } from '@angular/common'; import { CommonModule } from "@angular/common";
import { Component, Input, OnInit, ViewChild } from '@angular/core'; import { Component, Input, OnInit, ViewChild } from "@angular/core";
import { NWUIButtonComponent, NWUITextAreaComponent } from '@nwaifu-ui'; import { NWUIButtonComponent, NWUITextAreaComponent } from "@nwaifu-ui";
import { LocalStorageKeys } from '../../consts'; import { TranslationPipe } from "../../../../pipes/translation.pipe";
import { TranslateData } from '../../dto/translate_data.dto'; import { LocalStorageKeys } from "../../consts";
import { ETranslateService } from '../../services/translate.enums'; import { TranslateData } from "../../dto/translate_data.dto";
import { TranslateService } from '../../services/translate.service'; import { ETranslateService } from "../../services/translate.enums";
import { TranslateService } from "../../services/translate.service";
@Component({ @Component({
selector: 'app-translate-block', selector: "app-translate-block",
templateUrl: './translate_block.component.html', templateUrl: "./translate_block.component.html",
styleUrls: ['./translate_block.component.scss'], styleUrls: ["./translate_block.component.scss"],
standalone: true, standalone: true,
imports: [CommonModule, NWUIButtonComponent, NWUITextAreaComponent], imports: [CommonModule, NWUIButtonComponent, NWUITextAreaComponent, TranslationPipe],
providers: [TranslateService], providers: [TranslateService],
}) })
export class TranslateBlockComponent implements OnInit { export class TranslateBlockComponent implements OnInit {
@ViewChild('translatedText') translatedText: NWUITextAreaComponent | null = null; @ViewChild("translatedText") translatedText: NWUITextAreaComponent | null = null;
@Input({ required: true }) item: TranslateData = { english_text: '', translated_text: '' }; @Input({ required: true }) item: TranslateData = { english_text: "", translated_text: "" };
@Input({ required: true }) index = 0; @Input({ required: true }) index = 0;
translateLoading = false; translateLoading = false;
isEditing = false; isEditing = false;
saveChanges() { saveChanges() {
const data: TranslateData[] = JSON.parse(localStorage.getItem(LocalStorageKeys.TRANSLATIONS) ?? '[]'); const data: TranslateData[] = JSON.parse(
localStorage.getItem(LocalStorageKeys.TRANSLATIONS) ?? "[]",
);
if (!data.length) { if (!data.length) {
alert('No data'); alert("No data");
return; return;
} }
data[this.index] = this.item; data[this.index] = this.item;
localStorage.setItem('translations', JSON.stringify(data)); localStorage.setItem("translations", JSON.stringify(data));
} }
ngOnInit(): void { ngOnInit(): void {
this.isEditing = this.item.translated_text === ''; this.isEditing = this.item.translated_text === "";
} }
constructor(private translateService: TranslateService) {} constructor(private translateService: TranslateService) {}
@@ -40,7 +43,8 @@ export class TranslateBlockComponent implements OnInit {
private sendToTranslate(service: ETranslateService = ETranslateService.GOOGLE) { private sendToTranslate(service: ETranslateService = ETranslateService.GOOGLE) {
this.translateLoading = true; this.translateLoading = true;
this.translateService.translate(this.item.english_text, service).subscribe((text) => { this.translateService.translate(this.item.english_text, service).subscribe((text) => {
if (this.translatedText) if (this.translatedText.ref) this.translatedText.ref.nativeElement.textContent = text; if (this.translatedText)
if (this.translatedText.ref) this.translatedText.ref.nativeElement.textContent = text;
this.item.translated_text = text; this.item.translated_text = text;
this.isEditing = false; this.isEditing = false;
this.translateLoading = false; this.translateLoading = false;
@@ -62,14 +66,16 @@ export class TranslateBlockComponent implements OnInit {
saveTranslate(text: string) { saveTranslate(text: string) {
this.isEditing = false; this.isEditing = false;
if (this.translatedText) if (this.translatedText.ref) this.translatedText.ref.nativeElement.textContent = ''; if (this.translatedText)
if (this.translatedText.ref) this.translatedText.ref.nativeElement.textContent = "";
this.item.translated_text = text; this.item.translated_text = text;
this.saveChanges(); this.saveChanges();
} }
clear() { clear() {
this.item.translated_text = ''; this.item.translated_text = "";
this.isEditing = true; this.isEditing = true;
if (this.translatedText) if (this.translatedText.ref) this.translatedText.ref.nativeElement.textContent = ''; if (this.translatedText)
if (this.translatedText.ref) this.translatedText.ref.nativeElement.textContent = "";
this.saveChanges(); this.saveChanges();
} }
} }

View File

@@ -1,7 +1,7 @@
<div class="btns"> <div class="btns">
<div id="op_btns"> <div id="op_btns">
<nwui-button (click)="fileInput.click()"> <nwui-button (click)="fileInput.click()">
<span><i class="lni lni-upload"></i> Upload</span> <span><i class="lni lni-upload"></i> {{ "UPLOAD_BTN" | translate }}</span>
<input <input
type="file" type="file"
(change)="submitFile($event)" (change)="submitFile($event)"
@@ -11,17 +11,17 @@
/> />
</nwui-button> </nwui-button>
<nwui-button (click)="onSaveClicked()"> <nwui-button (click)="onSaveClicked()">
<span><i class="lni lni-save"></i> Save</span> <span><i class="lni lni-save"></i> {{ "SAVE_BTN" | translate }}</span>
</nwui-button> </nwui-button>
@if (this.elements.length) { @if (this.elements.length) {
<nwui-button (click)="clearAllTranslations()" [disabled]="!has_translations"> <nwui-button (click)="clearAllTranslations()" [disabled]="!has_translations">
<span><i class="lni lni-trash-can"></i> Clear translations</span> <span><i class="lni lni-trash-can"></i> {{ "CLEAR_TRANSLATIONS_BTN" | translate }}</span>
</nwui-button> </nwui-button>
<nwui-button (click)="getAllTranslations()"> <nwui-button (click)="getAllTranslations()">
<span><i class="lni lni-google"></i> Translate all</span> <span><i class="lni lni-google"></i> {{ "TRANSLATE_ALL_BTN" | translate }}</span>
</nwui-button> </nwui-button>
<nwui-button (click)="onClearClicked()"> <nwui-button (click)="onClearClicked()">
<span><i class="lni lni-trash-can"></i> Clear</span> <span><i class="lni lni-trash-can"></i> {{ "CLEAR_BTN" | translate }}</span>
</nwui-button> </nwui-button>
} }
</div> </div>

View File

@@ -3,6 +3,7 @@ import { AfterViewInit, Component, OnInit, ViewChild } from "@angular/core";
import { Router } from "@angular/router"; import { Router } from "@angular/router";
import { NWUIButtonComponent } from "@nwaifu-ui"; import { NWUIButtonComponent } from "@nwaifu-ui";
import { fromEvent, map } from "rxjs"; import { fromEvent, map } from "rxjs";
import { TranslationPipe } from "../../pipes/translation.pipe";
import { TextListComponent } from "./components/text_list/text_list.component"; import { TextListComponent } from "./components/text_list/text_list.component";
import { LocalStorageKeys } from "./consts"; import { LocalStorageKeys } from "./consts";
import { NpsFile, TranslateData } from "./dto/translate_data.dto"; import { NpsFile, TranslateData } from "./dto/translate_data.dto";
@@ -10,7 +11,7 @@ import { saveOriginalFile } from "./lib/file_tools";
import { parse } from "./lib/parser"; import { parse } from "./lib/parser";
@Component({ @Component({
standalone: true, standalone: true,
imports: [TextListComponent, CommonModule, NWUIButtonComponent], imports: [TextListComponent, CommonModule, NWUIButtonComponent, TranslationPipe],
selector: "app-nitroplus", selector: "app-nitroplus",
templateUrl: "./nitroplus-translator.component.html", templateUrl: "./nitroplus-translator.component.html",
styleUrl: "./nitroplus-translator.component.less", styleUrl: "./nitroplus-translator.component.less",

View File

@@ -5,5 +5,15 @@
"TELEGRAM_LABEL": "Telegram channel", "TELEGRAM_LABEL": "Telegram channel",
"GITHUB_LABEL": "Admin's Github", "GITHUB_LABEL": "Admin's Github",
"GITEA_LABEL": "Neuro LLC Gitea", "GITEA_LABEL": "Neuro LLC Gitea",
"SOURCE_CODE_TITLE": "Source code" "SOURCE_CODE_TITLE": "Source code",
"UPLOAD_BTN": "Upload",
"SAVE_BTN": "Save",
"CLEAR_TRANSLATIONS_BTN": "Clear translations",
"CLEAR_BTN": "Clear",
"ROW_COUNT_LABEL": "Row count",
"FILE_NAME_LABEL": "File name",
"TRANSLATE_BTN": "Translate",
"EDIT_BTN": "Edit",
"CLEAR_ROW_BTN": "Clear",
"TRANSLATE_ALL_BTN": "Translate all"
} }

View File

@@ -5,5 +5,15 @@
"TELEGRAM_LABEL": "Telegramチャンネル", "TELEGRAM_LABEL": "Telegramチャンネル",
"GITHUB_LABEL": "管理者Github", "GITHUB_LABEL": "管理者Github",
"GITEA_LABEL": "Neuro LLC Gitea", "GITEA_LABEL": "Neuro LLC Gitea",
"SOURCE_CODE_TITLE": "ソースコード" "SOURCE_CODE_TITLE": "ソースコード",
"UPLOAD_BTN": "アップロード",
"SAVE_BTN": "保存",
"CLEAR_TRANSLATIONS_BTN": "翻訳をクリア",
"CLEAR_BTN": "クリア",
"ROW_COUNT_LABEL": "行数",
"FILE_NAME_LABEL": "ファイル名",
"TRANSLATE_BTN": "翻訳",
"EDIT_BTN": "編集",
"CLEAR_ROW_BTN": "クリア",
"TRANSLATE_ALL_BTN": "すべて翻訳"
} }

View File

@@ -5,5 +5,15 @@
"TELEGRAM_LABEL": "Телеграм канал", "TELEGRAM_LABEL": "Телеграм канал",
"GITHUB_LABEL": "Github админа", "GITHUB_LABEL": "Github админа",
"GITEA_LABEL": "Neuro LLC Gitea", "GITEA_LABEL": "Neuro LLC Gitea",
"SOURCE_CODE_TITLE": "Исходный код" "SOURCE_CODE_TITLE": "Исходный код",
"UPLOAD_BTN": "Загрузить",
"SAVE_BTN": "Сохранить",
"CLEAR_TRANSLATIONS_BTN": "Очистить переводы",
"CLEAR_BTN": "Очистить",
"ROW_COUNT_LABEL": "Количество строк",
"FILE_NAME_LABEL": "Имя файла",
"TRANSLATE_BTN": "Перевести",
"EDIT_BTN": "Редактировать",
"CLEAR_ROW_BTN": "Очистить",
"TRANSLATE_ALL_BTN": "Перевести все"
} }

View File

@@ -1,6 +1,6 @@
{ {
"name": "nwaifu-web", "name": "nwaifu-web",
"version": "0.0.1", "version": "0.2.2",
"scripts": { "scripts": {
"ng": "ng", "ng": "ng",
"start": "nx serve NwaifuWeb", "start": "nx serve NwaifuWeb",