Compare commits
7 Commits
v0.2.0
...
27f023964f
| Author | SHA1 | Date | |
|---|---|---|---|
| 27f023964f | |||
| b43c8db305 | |||
| e3fc28e440 | |||
| c9638403ab | |||
| 02ae9c6745 | |||
| c8cb378123 | |||
| 47060bcb2d |
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
@@ -8,5 +8,6 @@
|
||||
"**/Thumbs.db": true,
|
||||
// "**/node_modules": true,
|
||||
"**/.angular": true
|
||||
}
|
||||
},
|
||||
"editor.formatOnSave": true
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<header>
|
||||
<app-panel></app-panel>
|
||||
</header>
|
||||
<main class="main">
|
||||
<main>
|
||||
<router-outlet></router-outlet>
|
||||
</main>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
.main {
|
||||
display: block;
|
||||
main {
|
||||
overflow-y: auto;
|
||||
width: 100%;
|
||||
height: calc(100% - 2rem);
|
||||
background-image: url("../assets/img/wallpaper.png");
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Component } from "@angular/core";
|
||||
import { RouterModule } from '@angular/router';
|
||||
import { RouterModule } from "@angular/router";
|
||||
import { PanelComponent } from "./modules/panel/panel.component";
|
||||
|
||||
@Component({
|
||||
|
||||
@@ -3,7 +3,15 @@
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 3rem;
|
||||
height: 3rem;
|
||||
width: 5rem;
|
||||
height: 6rem;
|
||||
color: white;
|
||||
font-size: 0.7rem;
|
||||
user-select: none;
|
||||
padding: 1rem;
|
||||
border-radius: 10px;
|
||||
transition: 0.2s ease-in-out;
|
||||
&:hover {
|
||||
background-color: rgba(25, 17, 19, 0.7);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
<h1 *ngIf="elements_data.length">Всего: {{ elements_data.length }}</h1>
|
||||
@if (elements_data.length) {
|
||||
<h1>Всего: {{ elements_data.length }}</h1>
|
||||
<h2>Файл: {{ fileName }}</h2>
|
||||
}
|
||||
<div id="elements">
|
||||
@for(item of elements_data; track $index) {
|
||||
<app-translate-block #translateBlock [index]="$index" [item]="item"></app-translate-block>
|
||||
@for (item of elements_data; track $index) {
|
||||
<app-translate-block #translateBlock [index]="$index" [item]="item"></app-translate-block>
|
||||
}
|
||||
</div>
|
||||
|
||||
@@ -6,13 +6,7 @@
|
||||
margin-inline: 2rem;
|
||||
}
|
||||
|
||||
// fix scroll on router click
|
||||
:host {
|
||||
overflow-y: scroll;
|
||||
height: fit-content;
|
||||
}
|
||||
|
||||
h1 {
|
||||
h1, h2 {
|
||||
color: #efdee0;
|
||||
text-align: center;
|
||||
margin: 1rem 2rem;
|
||||
|
||||
@@ -1,24 +1,34 @@
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { Component, Input, QueryList, ViewChildren } from '@angular/core';
|
||||
import { TranslateData } from '../../dto/translate_data.dto';
|
||||
import { TranslateBlockComponent } from '../translate_block/translate_block.component';
|
||||
import { CommonModule } from "@angular/common";
|
||||
import { Component, Input, OnInit, QueryList, ViewChildren } from "@angular/core";
|
||||
import { NpsFile, TranslateData } from "../../dto/translate_data.dto";
|
||||
import { TranslateBlockComponent } from "../translate_block/translate_block.component";
|
||||
|
||||
@Component({
|
||||
selector: 'app-text-list',
|
||||
templateUrl: './text_list.component.html',
|
||||
styleUrls: ['./text_list.component.scss'],
|
||||
selector: "app-text-list",
|
||||
templateUrl: "./text_list.component.html",
|
||||
styleUrls: ["./text_list.component.scss"],
|
||||
standalone: true,
|
||||
imports: [CommonModule, TranslateBlockComponent],
|
||||
})
|
||||
export class TextListComponent {
|
||||
@ViewChildren('translateBlock') translate_blocks: QueryList<TranslateBlockComponent> | null = null;
|
||||
export class TextListComponent implements OnInit {
|
||||
@ViewChildren("translateBlock") translate_blocks: QueryList<TranslateBlockComponent> | null =
|
||||
null;
|
||||
fileName = "";
|
||||
elements_data: TranslateData[] = [];
|
||||
@Input() set elements(el: TranslateData[]) {
|
||||
this.elements_data = el;
|
||||
localStorage.setItem('translations', JSON.stringify(this.elements_data));
|
||||
localStorage.setItem("translations", JSON.stringify(this.elements_data));
|
||||
}
|
||||
|
||||
get elements() {
|
||||
return this.elements_data;
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
const data = localStorage.getItem("original_file");
|
||||
if (data) {
|
||||
const file: NpsFile = JSON.parse(data);
|
||||
this.fileName = file.file_name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +1,22 @@
|
||||
import { TranslateData } from '../dto/translate_data.dto';
|
||||
import { TranslateData } from "../dto/translate_data.dto";
|
||||
|
||||
export function parse(text: string): TranslateData[] {
|
||||
const replaced_text = text
|
||||
.replace('/<[kK]{1}>/gm', '\n')
|
||||
.replace(/(<[^>]*>|\/\/.*)/gm, '')
|
||||
.replace(/\s*\n\s*/gm, '\n');
|
||||
const result = replaced_text
|
||||
.split('\n')
|
||||
.map((line) => line.trim())
|
||||
.filter((line) => line.length > 0)
|
||||
.map((line) => ({ english_text: line, translated_text: '' }));
|
||||
// Find all TEXT attr data
|
||||
const result: TranslateData[] = [];
|
||||
const re = /<[^>]*TEXT="(?<textAttr>[^>"]+)"[^>]*>|<[^>]*>|\/\/.*|\s*\n\s*/gm;
|
||||
for (const match of text.matchAll(re)) {
|
||||
if (match.groups?.["textAttr"])
|
||||
result.push({ english_text: match.groups?.["textAttr"], translated_text: "" });
|
||||
}
|
||||
|
||||
const replaced_text = text.replace(re, "\n").replace(/\s*\n\s*/gm, "\n");
|
||||
result.push(
|
||||
...replaced_text
|
||||
.split("\n")
|
||||
.map((line) => line.trim())
|
||||
.filter((line) => line.length > 0)
|
||||
.map((line) => ({ english_text: line, translated_text: "" })),
|
||||
);
|
||||
console.log(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -1,21 +1,33 @@
|
||||
<div class="btns">
|
||||
<nwui-button (click)="fileInput.click()">
|
||||
<span><i class="lni lni-upload"></i> Upload</span>
|
||||
<input type="file" (change)="submitFile($event)" accept=".nps" #fileInput style="display: none" />
|
||||
</nwui-button>
|
||||
<nwui-button (click)="onSaveClicked()">
|
||||
<span><i class="lni lni-save"></i> Save</span>
|
||||
</nwui-button>
|
||||
@if (this.elements.length){
|
||||
<nwui-button (click)="clearAllTranslations()" [disabled]="!has_translations">
|
||||
<span><i class="lni lni-trash-can"></i> Clear translations</span>
|
||||
</nwui-button>
|
||||
<nwui-button (click)="getAllTranslations()">
|
||||
<span><i class="lni lni-google"></i> Translate all</span>
|
||||
</nwui-button>
|
||||
<nwui-button (click)="onClearClicked()">
|
||||
<span><i class="lni lni-trash-can"></i> Clear</span>
|
||||
</nwui-button>
|
||||
}
|
||||
<div id="op_btns">
|
||||
<nwui-button (click)="fileInput.click()">
|
||||
<span><i class="lni lni-upload"></i> Upload</span>
|
||||
<input
|
||||
type="file"
|
||||
(change)="submitFile($event)"
|
||||
accept=".nps"
|
||||
#fileInput
|
||||
style="display: none"
|
||||
/>
|
||||
</nwui-button>
|
||||
<nwui-button (click)="onSaveClicked()">
|
||||
<span><i class="lni lni-save"></i> Save</span>
|
||||
</nwui-button>
|
||||
@if (this.elements.length) {
|
||||
<nwui-button (click)="clearAllTranslations()" [disabled]="!has_translations">
|
||||
<span><i class="lni lni-trash-can"></i> Clear translations</span>
|
||||
</nwui-button>
|
||||
<nwui-button (click)="getAllTranslations()">
|
||||
<span><i class="lni lni-google"></i> Translate all</span>
|
||||
</nwui-button>
|
||||
<nwui-button (click)="onClearClicked()">
|
||||
<span><i class="lni lni-trash-can"></i> Clear</span>
|
||||
</nwui-button>
|
||||
}
|
||||
</div>
|
||||
<button id="close_win" (click)="onCloseClicked()"><i class="lni lni-close"></i></button>
|
||||
</div>
|
||||
<app-text-list [elements]="elements"></app-text-list>
|
||||
<nwui-button class="to-top-btn" (click)="scrollToTop()"
|
||||
><i class="lni lni-arrow-up"></i
|
||||
></nwui-button>
|
||||
|
||||
@@ -1,14 +1,58 @@
|
||||
.btns {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
justify-content: flex-start;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
width: 100%;
|
||||
overflow-x: auto;
|
||||
scrollbar-color: #413738;
|
||||
nwui-button {
|
||||
margin: 2rem;
|
||||
}
|
||||
#op_btns {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
justify-content: flex-start;
|
||||
align-items: center;
|
||||
}
|
||||
#close_win {
|
||||
color: var(--white);
|
||||
font-weight: 600;
|
||||
margin-inline: 2rem;
|
||||
background-color: #413738;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
padding: 0.5rem;
|
||||
border-radius: 50px;
|
||||
transition: 0.2s linear;
|
||||
i {
|
||||
transition: 0.3s linear;
|
||||
}
|
||||
&:hover {
|
||||
background-color: #5b3f45;
|
||||
transform: scale(1.1);
|
||||
i {
|
||||
transform: scale(1.1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
:host {
|
||||
background-color: #191113;
|
||||
display: block;
|
||||
min-height: calc(100vh - 2rem);
|
||||
scrollbar-color: #413738;
|
||||
}
|
||||
.to-top-btn {
|
||||
position: fixed;
|
||||
width: 2rem;
|
||||
left: 2rem;
|
||||
bottom: -5rem;
|
||||
transition: bottom 0.3s ease-in-out;
|
||||
|
||||
&.active {
|
||||
bottom: 1rem;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,24 +1,28 @@
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { Component, OnInit, ViewChild } from '@angular/core';
|
||||
import { NWUIButtonComponent } from '@nwaifu-ui';
|
||||
import { TextListComponent } from './components/text_list/text_list.component';
|
||||
import { LocalStorageKeys } from './consts';
|
||||
import { NpsFile, TranslateData } from './dto/translate_data.dto';
|
||||
import { saveOriginalFile } from './lib/file_tools';
|
||||
import { parse } from './lib/parser';
|
||||
import { CommonModule } from "@angular/common";
|
||||
import { AfterViewInit, Component, OnInit, ViewChild } from "@angular/core";
|
||||
import { Router } from "@angular/router";
|
||||
import { NWUIButtonComponent } from "@nwaifu-ui";
|
||||
import { fromEvent, map } from "rxjs";
|
||||
import { TextListComponent } from "./components/text_list/text_list.component";
|
||||
import { LocalStorageKeys } from "./consts";
|
||||
import { NpsFile, TranslateData } from "./dto/translate_data.dto";
|
||||
import { saveOriginalFile } from "./lib/file_tools";
|
||||
import { parse } from "./lib/parser";
|
||||
@Component({
|
||||
standalone: true,
|
||||
imports: [TextListComponent, CommonModule, NWUIButtonComponent],
|
||||
selector: 'app-nitroplus',
|
||||
templateUrl: './nitroplus-translator.component.html',
|
||||
styleUrl: './nitroplus-translator.component.less',
|
||||
selector: "app-nitroplus",
|
||||
templateUrl: "./nitroplus-translator.component.html",
|
||||
styleUrl: "./nitroplus-translator.component.less",
|
||||
})
|
||||
export class NitroplusComponent implements OnInit {
|
||||
title = 'NitroPlusTranslator';
|
||||
export class NitroplusComponent implements OnInit, AfterViewInit {
|
||||
title = "NitroPlusTranslator";
|
||||
elements: TranslateData[] = [];
|
||||
@ViewChild('fileInput') fileInput: HTMLInputElement | null = null;
|
||||
@ViewChild("fileInput") fileInput: HTMLInputElement | null = null;
|
||||
@ViewChild(TextListComponent) text_list: TextListComponent | null = null;
|
||||
|
||||
constructor(private readonly router: Router) {}
|
||||
|
||||
ngOnInit(): void {
|
||||
const data = localStorage.getItem(LocalStorageKeys.TRANSLATIONS);
|
||||
if (data) {
|
||||
@@ -26,13 +30,32 @@ export class NitroplusComponent implements OnInit {
|
||||
this.elements = JSON.parse(data);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
alert('Error while loading');
|
||||
alert("Error while loading");
|
||||
localStorage.removeItem(LocalStorageKeys.TRANSLATIONS);
|
||||
this.elements = [];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ngAfterViewInit(): void {
|
||||
const container = document.querySelector("main");
|
||||
if (container) {
|
||||
fromEvent(container, "scroll")
|
||||
.pipe(map(() => container.scrollTop > 100))
|
||||
.subscribe((val) => {
|
||||
if (val) document.querySelector(".to-top-btn")?.classList.add("active");
|
||||
else document.querySelector(".to-top-btn")?.classList.remove("active");
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
scrollToTop() {
|
||||
const container = document.querySelector("main");
|
||||
if (container) {
|
||||
container.scrollTo({ top: 0, behavior: "smooth" });
|
||||
}
|
||||
}
|
||||
|
||||
submitFile($event: Event) {
|
||||
const target = $event.target as HTMLInputElement;
|
||||
if (target.files) {
|
||||
@@ -47,7 +70,7 @@ export class NitroplusComponent implements OnInit {
|
||||
original_text: reader.result.toString(),
|
||||
};
|
||||
saveOriginalFile(original_file);
|
||||
target.value = '';
|
||||
target.value = "";
|
||||
}
|
||||
};
|
||||
reader.readAsText(file);
|
||||
@@ -67,21 +90,27 @@ export class NitroplusComponent implements OnInit {
|
||||
|
||||
onSaveClicked() {
|
||||
const original_file: NpsFile = JSON.parse(
|
||||
localStorage.getItem(LocalStorageKeys.ORIGINAL_FILE) ?? '{"file_name":"", "original_text":""}',
|
||||
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) ?? '[]');
|
||||
const data: TranslateData[] = JSON.parse(
|
||||
localStorage.getItem(LocalStorageKeys.TRANSLATIONS) ?? "[]",
|
||||
);
|
||||
if (!data.length) {
|
||||
alert('No data');
|
||||
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);
|
||||
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' });
|
||||
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();
|
||||
@@ -92,7 +121,9 @@ export class NitroplusComponent implements OnInit {
|
||||
clearAllTranslations() {
|
||||
if (this.text_list)
|
||||
if (this.text_list.translate_blocks) {
|
||||
this.text_list.translate_blocks.filter((item) => item.item.translated_text).forEach((item) => item.clear());
|
||||
this.text_list.translate_blocks
|
||||
.filter((item) => item.item.translated_text)
|
||||
.forEach((item) => item.clear());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -105,4 +136,8 @@ export class NitroplusComponent implements OnInit {
|
||||
get has_translations(): boolean {
|
||||
return this.elements.some((i) => i.translated_text);
|
||||
}
|
||||
|
||||
onCloseClicked() {
|
||||
this.router.navigate(["/"]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,16 +25,10 @@
|
||||
font-weight: 400;
|
||||
font-style: normal;
|
||||
}
|
||||
html {
|
||||
position: relative;
|
||||
height: 100%;
|
||||
}
|
||||
body {
|
||||
html, body {
|
||||
width: 100%;
|
||||
height: 100vh;
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
height: 100%;
|
||||
position: relative;
|
||||
}
|
||||
ngneat-dialog {
|
||||
.ngneat-dialog-backdrop {
|
||||
|
||||
@@ -3,10 +3,15 @@ button {
|
||||
border: none;
|
||||
cursor: pointer;
|
||||
background-color: #5b3f45;
|
||||
word-break: keep-all;
|
||||
padding: 1em 1.5em;
|
||||
color: #f5f6fa;
|
||||
border-radius: 15px;
|
||||
transition: ease-in-out 0.2s;
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 100%;
|
||||
&:hover,
|
||||
&:active {
|
||||
|
||||
15912
pnpm-lock.yaml
generated
15912
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user