feat: saving original file
This commit is contained in:
@@ -1,7 +1,9 @@
|
|||||||
import { Component, OnInit, ViewChild } from '@angular/core';
|
import { Component, OnInit, ViewChild } from '@angular/core';
|
||||||
import { NWUIButtonComponent } from '@nwaifu-ui';
|
import { NWUIButtonComponent } 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,
|
||||||
@@ -16,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 = [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -38,6 +40,11 @@ export class AppComponent implements OnInit {
|
|||||||
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 = '';
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -53,6 +60,6 @@ export class AppComponent implements OnInit {
|
|||||||
|
|
||||||
onClearClicked() {
|
onClearClicked() {
|
||||||
this.elements = [];
|
this.elements = [];
|
||||||
localStorage.removeItem('translations');
|
localStorage.removeItem(LocalStorageKeys.TRANSLATIONS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { CommonModule } from '@angular/common';
|
import { CommonModule } from '@angular/common';
|
||||||
import { Component, ElementRef, Input, OnInit, ViewChild } from '@angular/core';
|
import { Component, ElementRef, Input, OnInit, ViewChild } from '@angular/core';
|
||||||
import { NWUIButtonComponent, NWUITextAreaComponent } 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 { ETranslateService } from '../../services/translate.enums';
|
import { ETranslateService } from '../../services/translate.enums';
|
||||||
import { TranslateService } from '../../services/translate.service';
|
import { TranslateService } from '../../services/translate.service';
|
||||||
@@ -21,7 +22,7 @@ export class TranslateBlockComponent implements OnInit {
|
|||||||
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;
|
||||||
|
|||||||
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));
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user