Merge branch 'feature/save-original-file' into dev
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -40,3 +40,5 @@ Thumbs.db
|
|||||||
|
|
||||||
.nx/cache
|
.nx/cache
|
||||||
.angular
|
.angular
|
||||||
|
|
||||||
|
*.nps
|
||||||
@@ -5,5 +5,9 @@
|
|||||||
"tabWidth": 2,
|
"tabWidth": 2,
|
||||||
"bracketSpacing": true,
|
"bracketSpacing": true,
|
||||||
"endOfLine": "lf",
|
"endOfLine": "lf",
|
||||||
"semi": true
|
"semi": true,
|
||||||
|
"arrowParens": "always",
|
||||||
|
"bracketSameLine": false,
|
||||||
|
"insertPragma": false,
|
||||||
|
"useTabs": false
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ button {
|
|||||||
color: #f5f6fa;
|
color: #f5f6fa;
|
||||||
border-radius: 15px;
|
border-radius: 15px;
|
||||||
transition: ease-in-out 0.2s;
|
transition: ease-in-out 0.2s;
|
||||||
margin: 2rem;
|
width: 100%;
|
||||||
&:hover,
|
&:hover,
|
||||||
&:active {
|
&:active {
|
||||||
transform: scale(1.2);
|
transform: scale(1.2);
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import { ChangeDetectionStrategy, Component, Input } from '@angular/core';
|
|||||||
imports: [CommonModule],
|
imports: [CommonModule],
|
||||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||||
})
|
})
|
||||||
export class ButtonComponent {
|
export class NWUIButtonComponent {
|
||||||
@Input() disabled = false;
|
@Input() disabled = false;
|
||||||
@Input() type: string | undefined;
|
@Input() type = 'button';
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1 +1,2 @@
|
|||||||
export * from './button';
|
export * from './button';
|
||||||
|
export * from './textarea';
|
||||||
|
|||||||
1
nwaifu-ui/src/lib/components/textarea/index.ts
Normal file
1
nwaifu-ui/src/lib/components/textarea/index.ts
Normal file
@@ -0,0 +1 @@
|
|||||||
|
export * from './textarea.component';
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
<div [attr.contenteditable]="contenteditable" [className]="className" #ref (blur)="leaveFn()">
|
||||||
|
@if(!value) {
|
||||||
|
<ng-content></ng-content>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
.nwui-textarea {
|
||||||
|
border-radius: 8px;
|
||||||
|
height: auto;
|
||||||
|
color: #efdee0;
|
||||||
|
outline: none;
|
||||||
|
padding-inline: 2rem 1rem;
|
||||||
|
background-color: transparent;
|
||||||
|
border: 2px solid #e4bdc3;
|
||||||
|
font-size: 1rem;
|
||||||
|
font-weight: inherit;
|
||||||
|
min-height: 3rem;
|
||||||
|
line-height: 3rem;
|
||||||
|
&:focus {
|
||||||
|
border: 2px solid #efdee0;
|
||||||
|
}
|
||||||
|
&.disabled {
|
||||||
|
opacity: 0.5;
|
||||||
|
}
|
||||||
|
word-wrap: break-word;
|
||||||
|
}
|
||||||
36
nwaifu-ui/src/lib/components/textarea/textarea.component.ts
Normal file
36
nwaifu-ui/src/lib/components/textarea/textarea.component.ts
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
import { CommonModule } from '@angular/common';
|
||||||
|
import { AfterViewInit, Component, ElementRef, EventEmitter, Input, Output, ViewChild } from '@angular/core';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'nwui-textarea',
|
||||||
|
imports: [CommonModule],
|
||||||
|
standalone: true,
|
||||||
|
styleUrls: ['./textarea.component.scss'],
|
||||||
|
templateUrl: './textarea.component.html',
|
||||||
|
// changeDetection: ChangeDetectionStrategy.OnPush,
|
||||||
|
})
|
||||||
|
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;
|
||||||
|
|
||||||
|
get className(): string {
|
||||||
|
return `nwui-textarea ${this.disabled && !this.contenteditable ? 'disabled' : ''}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
leaveFn() {
|
||||||
|
if (this.ref) {
|
||||||
|
const target = this.ref.nativeElement;
|
||||||
|
const text = target.textContent || '';
|
||||||
|
if (this.leave) this.leave.emit(text);
|
||||||
|
target.textContent = text;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ngAfterViewInit(): void {
|
||||||
|
if (this.ref && this.value) this.ref.nativeElement.textContent = this.value;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,4 +8,3 @@
|
|||||||
</nwui-button>
|
</nwui-button>
|
||||||
</div>
|
</div>
|
||||||
<app-text-list [elements]="elements"></app-text-list>
|
<app-text-list [elements]="elements"></app-text-list>
|
||||||
<router-outlet></router-outlet>
|
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
.btns {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
justify-content: flex-start;
|
||||||
|
align-items: center;
|
||||||
|
nwui-button {
|
||||||
|
margin: 2rem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,12 +1,13 @@
|
|||||||
import { Component, OnInit, ViewChild } from '@angular/core';
|
import { Component, OnInit, ViewChild } from '@angular/core';
|
||||||
import { RouterModule } from '@angular/router';
|
import { NWUIButtonComponent } from '@nwaifu-ui';
|
||||||
import { ButtonComponent } from '@nwaifu-ui';
|
|
||||||
import { TextListComponent } from './components/text_list/text_list.component';
|
import { TextListComponent } from './components/text_list/text_list.component';
|
||||||
import { TranslateData } from './dto/translate_data.dto';
|
import { LocalStorageKeys } from './consts';
|
||||||
|
import { NpsFile, TranslateData } from './dto/translate_data.dto';
|
||||||
|
import { saveOriginalFile } from './lib/file_tools';
|
||||||
import { parse } from './lib/parser';
|
import { parse } from './lib/parser';
|
||||||
@Component({
|
@Component({
|
||||||
standalone: true,
|
standalone: true,
|
||||||
imports: [RouterModule, TextListComponent, ButtonComponent],
|
imports: [TextListComponent, NWUIButtonComponent],
|
||||||
selector: 'app-root',
|
selector: 'app-root',
|
||||||
templateUrl: './app.component.html',
|
templateUrl: './app.component.html',
|
||||||
styleUrl: './app.component.scss',
|
styleUrl: './app.component.scss',
|
||||||
@@ -17,14 +18,14 @@ export class AppComponent implements OnInit {
|
|||||||
@ViewChild('fileInput') fileInput: HTMLInputElement | null = null;
|
@ViewChild('fileInput') fileInput: HTMLInputElement | null = null;
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
const data = localStorage.getItem('translations');
|
const data = localStorage.getItem(LocalStorageKeys.TRANSLATIONS);
|
||||||
if (data) {
|
if (data) {
|
||||||
try {
|
try {
|
||||||
this.elements = JSON.parse(data);
|
this.elements = JSON.parse(data);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
alert('Error while loading');
|
alert('Error while loading');
|
||||||
localStorage.removeItem('translations');
|
localStorage.removeItem(LocalStorageKeys.TRANSLATIONS);
|
||||||
this.elements = [];
|
this.elements = [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -33,12 +34,17 @@ export class AppComponent implements OnInit {
|
|||||||
submitFile($event: Event) {
|
submitFile($event: Event) {
|
||||||
const target = $event.target as HTMLInputElement;
|
const target = $event.target as HTMLInputElement;
|
||||||
if (target.files) {
|
if (target.files) {
|
||||||
const file = target.files?.[0];
|
const file = target.files[0];
|
||||||
if (file) {
|
if (file) {
|
||||||
const reader = new FileReader();
|
const reader = new FileReader();
|
||||||
reader.onload = () => {
|
reader.onload = () => {
|
||||||
if (reader.result) {
|
if (reader.result) {
|
||||||
this.onFileLoaded(reader.result.toString());
|
this.onFileLoaded(reader.result.toString());
|
||||||
|
const original_file: NpsFile = {
|
||||||
|
file_name: file.name,
|
||||||
|
original_text: reader.result.toString(),
|
||||||
|
};
|
||||||
|
saveOriginalFile(original_file);
|
||||||
target.value = '';
|
target.value = '';
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -54,6 +60,6 @@ export class AppComponent implements OnInit {
|
|||||||
|
|
||||||
onClearClicked() {
|
onClearClicked() {
|
||||||
this.elements = [];
|
this.elements = [];
|
||||||
localStorage.removeItem('translations');
|
localStorage.removeItem(LocalStorageKeys.TRANSLATIONS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,6 @@
|
|||||||
import { provideHttpClient } from '@angular/common/http';
|
import { provideHttpClient } from '@angular/common/http';
|
||||||
import { ApplicationConfig } from '@angular/core';
|
import { ApplicationConfig } from '@angular/core';
|
||||||
import { provideRouter } from '@angular/router';
|
|
||||||
import { appRoutes } from './app.routes';
|
|
||||||
import { TranslateService } from './services/translate.service';
|
|
||||||
|
|
||||||
export const appConfig: ApplicationConfig = {
|
export const appConfig: ApplicationConfig = {
|
||||||
providers: [provideHttpClient(), provideRouter(appRoutes), TranslateService],
|
providers: [provideHttpClient()],
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,12 +1,18 @@
|
|||||||
<div class="element">
|
<div class="element">
|
||||||
<h2>{{ index + 1 }}</h2>
|
<h2>{{ index + 1 }}</h2>
|
||||||
<div class="fields">
|
<div class="fields">
|
||||||
<div class="english-text">{{ item.english_text }}</div>
|
<nwui-textarea [contenteditable]="false">{{ item.english_text }}</nwui-textarea>
|
||||||
<div class="translated-text" #translatedText [attr.contenteditable]="isEditing" (blur)="saveTranslate()"></div>
|
<nwui-textarea
|
||||||
|
#translatedText
|
||||||
|
[contenteditable]="isEditing"
|
||||||
|
(leave)="saveTranslate($event)"
|
||||||
|
[disabled]="!isEditing"
|
||||||
|
>{{ item.translated_text }}</nwui-textarea
|
||||||
|
>
|
||||||
</div>
|
</div>
|
||||||
<div class="btns">
|
<div class="btns">
|
||||||
<nwui-button (click)="sendToTranslate()">Translate</nwui-button>
|
<nwui-button (click)="sendToGoogleTranslate()" [disabled]="translateLoading">Translate</nwui-button>
|
||||||
<button (click)="isEditing = !isEditing" [disabled]="isEditing">Edit</button>
|
<nwui-button (click)="isEditing = !isEditing" [disabled]="isEditing">Edit</nwui-button>
|
||||||
<button (click)="clear()" [disabled]="!item.translated_text.length">Clear</button>
|
<nwui-button (click)="clear()" [disabled]="!item.translated_text.length">Clear</nwui-button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,34 +1,3 @@
|
|||||||
.translated-text {
|
|
||||||
border-radius: 8px;
|
|
||||||
height: auto;
|
|
||||||
color: #efdee0;
|
|
||||||
outline: none;
|
|
||||||
padding-inline: 2rem 1rem;
|
|
||||||
background-color: transparent;
|
|
||||||
border: 2px solid #e4bdc3;
|
|
||||||
font-size: 1rem;
|
|
||||||
font-weight: inherit;
|
|
||||||
min-height: 3rem;
|
|
||||||
line-height: 3rem;
|
|
||||||
&:focus {
|
|
||||||
border: 2px solid #efdee0;
|
|
||||||
}
|
|
||||||
&:read-only {
|
|
||||||
opacity: 0.5;
|
|
||||||
}
|
|
||||||
word-wrap: break-word;
|
|
||||||
}
|
|
||||||
|
|
||||||
.english-text {
|
|
||||||
color: #efdee0;
|
|
||||||
border: 2px solid #e4bdc3;
|
|
||||||
word-wrap: break-word;
|
|
||||||
border-radius: 8px;
|
|
||||||
padding-inline: 2rem 1rem;
|
|
||||||
line-height: 3rem;
|
|
||||||
background-color: transparent;
|
|
||||||
}
|
|
||||||
|
|
||||||
.element {
|
.element {
|
||||||
display: flex;
|
display: flex;
|
||||||
background-color: #413738;
|
background-color: #413738;
|
||||||
@@ -62,24 +31,9 @@
|
|||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
gap: 1rem;
|
gap: 1rem;
|
||||||
.btn {
|
align-items: center;
|
||||||
outline: none;
|
padding-inline: 1rem;
|
||||||
border: none;
|
nwui-button {
|
||||||
cursor: pointer;
|
width: 100%;
|
||||||
background-color: #5b3f45;
|
|
||||||
padding: 1em 1.5em;
|
|
||||||
color: #f5f6fa;
|
|
||||||
border-radius: 15px;
|
|
||||||
transition: ease-in-out 0.2s;
|
|
||||||
&:hover {
|
|
||||||
transform: scale(1.2);
|
|
||||||
}
|
|
||||||
&:disabled {
|
|
||||||
opacity: 0.5;
|
|
||||||
&:hover {
|
|
||||||
cursor: not-allowed;
|
|
||||||
transform: scale(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,25 +1,28 @@
|
|||||||
import { CommonModule } from '@angular/common';
|
import { CommonModule } from '@angular/common';
|
||||||
import { AfterViewInit, ChangeDetectorRef, Component, ElementRef, Input, OnInit, ViewChild } from '@angular/core';
|
import { Component, ElementRef, Input, OnInit, ViewChild } from '@angular/core';
|
||||||
import { ButtonComponent } from '@nwaifu-ui';
|
import { NWUIButtonComponent, NWUITextAreaComponent } from '@nwaifu-ui';
|
||||||
|
import { LocalStorageKeys } from 'src/app/consts';
|
||||||
import { TranslateData } from '../../dto/translate_data.dto';
|
import { TranslateData } from '../../dto/translate_data.dto';
|
||||||
import { TranslatePipe } from '../../pipes/translate.pipe';
|
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, ButtonComponent],
|
imports: [CommonModule, NWUIButtonComponent, NWUITextAreaComponent],
|
||||||
providers: [TranslatePipe],
|
providers: [TranslateService],
|
||||||
})
|
})
|
||||||
export class TranslateBlockComponent implements OnInit, AfterViewInit {
|
export class TranslateBlockComponent implements OnInit {
|
||||||
@ViewChild('translatedText') translatedText: ElementRef<HTMLDivElement> | null = null;
|
@ViewChild('translatedText') translatedText: ElementRef<HTMLDivElement> | null = null;
|
||||||
@Input() item: TranslateData = { english_text: '', translated_text: '' };
|
@Input({ required: true }) item: TranslateData = { english_text: '', translated_text: '' };
|
||||||
@Input() index = 0;
|
@Input({ required: true }) index = 0;
|
||||||
|
translateLoading = false;
|
||||||
isEditing = false;
|
isEditing = false;
|
||||||
|
|
||||||
saveChanges() {
|
saveChanges() {
|
||||||
const data: TranslateData[] = JSON.parse(localStorage.getItem('translations') ?? '[]');
|
const data: TranslateData[] = JSON.parse(localStorage.getItem(LocalStorageKeys.TRANSLATIONS) ?? '[]');
|
||||||
if (!data.length) {
|
if (!data.length) {
|
||||||
alert('No data');
|
alert('No data');
|
||||||
return;
|
return;
|
||||||
@@ -32,32 +35,38 @@ export class TranslateBlockComponent implements OnInit, AfterViewInit {
|
|||||||
this.isEditing = this.item.translated_text === '';
|
this.isEditing = this.item.translated_text === '';
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(private translatePipe: TranslatePipe, private changeDetectionRef: ChangeDetectorRef) {}
|
constructor(private translateService: TranslateService) {}
|
||||||
async sendToTranslate() {
|
|
||||||
const text = await this.translatePipe.transform(this.item.english_text);
|
private sendToTranslate(service: ETranslateService = ETranslateService.GOOGLE) {
|
||||||
this.item.translated_text = text;
|
this.translateLoading = true;
|
||||||
if (this.translatedText) this.translatedText.nativeElement.textContent = text;
|
this.translateService.translate(this.item.english_text, service).subscribe((text) => {
|
||||||
this.isEditing = false;
|
this.item.translated_text = text;
|
||||||
this.saveChanges();
|
this.isEditing = false;
|
||||||
|
this.translateLoading = false;
|
||||||
|
this.saveChanges();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
saveTranslate() {
|
sendToGoogleTranslate() {
|
||||||
|
this.sendToTranslate(ETranslateService.GOOGLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
sendToDeeplTranslate() {
|
||||||
|
this.sendToTranslate(ETranslateService.DEEPL);
|
||||||
|
}
|
||||||
|
|
||||||
|
sendToPromptTranslate() {
|
||||||
|
this.sendToTranslate(ETranslateService.PROMPT);
|
||||||
|
}
|
||||||
|
|
||||||
|
saveTranslate(text: string) {
|
||||||
this.isEditing = false;
|
this.isEditing = false;
|
||||||
if (this.translatedText) {
|
this.item.translated_text = text;
|
||||||
this.item.translated_text = this.translatedText.nativeElement.textContent || '';
|
|
||||||
this.translatedText.nativeElement.textContent = '';
|
|
||||||
this.translatedText.nativeElement.textContent = this.item.translated_text;
|
|
||||||
}
|
|
||||||
this.saveChanges();
|
this.saveChanges();
|
||||||
}
|
}
|
||||||
clear() {
|
clear() {
|
||||||
this.item.translated_text = '';
|
this.item.translated_text = '';
|
||||||
if (this.translatedText) this.translatedText.nativeElement.textContent = '';
|
|
||||||
this.isEditing = true;
|
this.isEditing = true;
|
||||||
this.saveChanges();
|
this.saveChanges();
|
||||||
}
|
}
|
||||||
|
|
||||||
ngAfterViewInit(): void {
|
|
||||||
if (this.translatedText) this.translatedText.nativeElement.textContent = this.item.translated_text;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
4
src/app/consts.ts
Normal file
4
src/app/consts.ts
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
export enum LocalStorageKeys {
|
||||||
|
TRANSLATIONS = 'translations',
|
||||||
|
ORIGINAL_FILE = 'original_file',
|
||||||
|
}
|
||||||
@@ -2,3 +2,8 @@ export interface TranslateData {
|
|||||||
english_text: string;
|
english_text: string;
|
||||||
translated_text: string;
|
translated_text: string;
|
||||||
}
|
}
|
||||||
|
export interface NpsFile {
|
||||||
|
file_name: string;
|
||||||
|
original_text: string;
|
||||||
|
translated_text?: string;
|
||||||
|
}
|
||||||
|
|||||||
6
src/app/lib/file_tools.ts
Normal file
6
src/app/lib/file_tools.ts
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
import { LocalStorageKeys } from '../consts';
|
||||||
|
import { NpsFile } from '../dto/translate_data.dto';
|
||||||
|
|
||||||
|
export function saveOriginalFile(file: NpsFile) {
|
||||||
|
localStorage.setItem(LocalStorageKeys.ORIGINAL_FILE, JSON.stringify(file));
|
||||||
|
}
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
import { Pipe, PipeTransform } from '@angular/core';
|
|
||||||
import { TranslateService } from '../services/translate.service';
|
|
||||||
|
|
||||||
@Pipe({ name: 'translate', standalone: true, pure: false })
|
|
||||||
export class TranslatePipe implements PipeTransform {
|
|
||||||
constructor(private translateService: TranslateService) {}
|
|
||||||
transform(text: string) {
|
|
||||||
return this.translateService.translate(text);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
1
src/app/services/translate.dto.ts
Normal file
1
src/app/services/translate.dto.ts
Normal file
@@ -0,0 +1 @@
|
|||||||
|
export type GoogleTranslateResponse = Array<Array<string>>;
|
||||||
5
src/app/services/translate.enums.ts
Normal file
5
src/app/services/translate.enums.ts
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
export enum ETranslateService {
|
||||||
|
GOOGLE = 'google',
|
||||||
|
DEEPL = 'deepl',
|
||||||
|
PROMPT = 'prompt',
|
||||||
|
}
|
||||||
@@ -1,27 +1,34 @@
|
|||||||
import { HttpClient } from '@angular/common/http';
|
import { HttpClient } from '@angular/common/http';
|
||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
|
import { Observable, map } from 'rxjs';
|
||||||
|
import { GoogleTranslateResponse } from './translate.dto';
|
||||||
|
import { ETranslateService } from './translate.enums';
|
||||||
|
|
||||||
@Injectable({ providedIn: 'root' })
|
@Injectable({ providedIn: 'root' })
|
||||||
export class TranslateService {
|
export class TranslateService {
|
||||||
constructor(private http: HttpClient) {}
|
constructor(private http: HttpClient) {}
|
||||||
translate(text: string): Promise<string> {
|
|
||||||
return new Promise<string>((resolve) => {
|
private googleTranslate(text: string): Observable<string> {
|
||||||
this.http
|
return this.http
|
||||||
.get(
|
.get<GoogleTranslateResponse>(
|
||||||
'https://translate.googleapis.com/translate_a/single?client=gtx&sl=en&tl=ru&dt=t&q=' +
|
'https://translate.googleapis.com/translate_a/single?client=gtx&sl=en&tl=ru&dt=t&q=' + encodeURIComponent(text),
|
||||||
encodeURIComponent(text),
|
)
|
||||||
)
|
.pipe(
|
||||||
.subscribe({
|
map((response) => {
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
let result = '';
|
||||||
next: (response: any) => {
|
response[0].forEach((el) => {
|
||||||
console.log(response);
|
result += el[0] + ' ';
|
||||||
resolve(response[0][0][0]);
|
});
|
||||||
},
|
return result;
|
||||||
error: (error) => {
|
}),
|
||||||
console.error(error);
|
);
|
||||||
resolve('');
|
}
|
||||||
},
|
translate(text: string, service: ETranslateService = ETranslateService.GOOGLE): Observable<string> {
|
||||||
});
|
switch (service) {
|
||||||
});
|
case ETranslateService.GOOGLE:
|
||||||
|
return this.googleTranslate(text);
|
||||||
|
default:
|
||||||
|
return this.googleTranslate(text);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user