Compare commits
5 Commits
c8cb378123
...
27f023964f
| Author | SHA1 | Date | |
|---|---|---|---|
| 27f023964f | |||
| b43c8db305 | |||
| e3fc28e440 | |||
| c9638403ab | |||
| 02ae9c6745 |
@@ -1,5 +1,5 @@
|
|||||||
import { Component } from "@angular/core";
|
import { Component } from "@angular/core";
|
||||||
import { RouterModule } from '@angular/router';
|
import { RouterModule } from "@angular/router";
|
||||||
import { PanelComponent } from "./modules/panel/panel.component";
|
import { PanelComponent } from "./modules/panel/panel.component";
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
|
|||||||
@@ -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">
|
<div id="elements">
|
||||||
@for(item of elements_data; track $index) {
|
@for (item of elements_data; track $index) {
|
||||||
<app-translate-block #translateBlock [index]="$index" [item]="item"></app-translate-block>
|
<app-translate-block #translateBlock [index]="$index" [item]="item"></app-translate-block>
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
margin-inline: 2rem;
|
margin-inline: 2rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
h1 {
|
h1, h2 {
|
||||||
color: #efdee0;
|
color: #efdee0;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
margin: 1rem 2rem;
|
margin: 1rem 2rem;
|
||||||
|
|||||||
@@ -1,24 +1,34 @@
|
|||||||
import { CommonModule } from '@angular/common';
|
import { CommonModule } from "@angular/common";
|
||||||
import { Component, Input, QueryList, ViewChildren } from '@angular/core';
|
import { Component, Input, OnInit, QueryList, ViewChildren } from "@angular/core";
|
||||||
import { 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";
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-text-list',
|
selector: "app-text-list",
|
||||||
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],
|
||||||
})
|
})
|
||||||
export class TextListComponent {
|
export class TextListComponent implements OnInit {
|
||||||
@ViewChildren('translateBlock') translate_blocks: QueryList<TranslateBlockComponent> | null = null;
|
@ViewChildren("translateBlock") translate_blocks: QueryList<TranslateBlockComponent> | null =
|
||||||
|
null;
|
||||||
|
fileName = "";
|
||||||
elements_data: TranslateData[] = [];
|
elements_data: TranslateData[] = [];
|
||||||
@Input() set elements(el: TranslateData[]) {
|
@Input() set elements(el: TranslateData[]) {
|
||||||
this.elements_data = el;
|
this.elements_data = el;
|
||||||
localStorage.setItem('translations', JSON.stringify(this.elements_data));
|
localStorage.setItem("translations", JSON.stringify(this.elements_data));
|
||||||
}
|
}
|
||||||
|
|
||||||
get elements() {
|
get elements() {
|
||||||
return this.elements_data;
|
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[] {
|
export function parse(text: string): TranslateData[] {
|
||||||
const replaced_text = text
|
// Find all TEXT attr data
|
||||||
.replace('/<[kK]{1}>/gm', '\n')
|
const result: TranslateData[] = [];
|
||||||
.replace(/(<[^>]*>|\/\/.*)/gm, '')
|
const re = /<[^>]*TEXT="(?<textAttr>[^>"]+)"[^>]*>|<[^>]*>|\/\/.*|\s*\n\s*/gm;
|
||||||
.replace(/\s*\n\s*/gm, '\n');
|
for (const match of text.matchAll(re)) {
|
||||||
const result = replaced_text
|
if (match.groups?.["textAttr"])
|
||||||
.split('\n')
|
result.push({ english_text: match.groups?.["textAttr"], translated_text: "" });
|
||||||
.map((line) => line.trim())
|
}
|
||||||
.filter((line) => line.length > 0)
|
|
||||||
.map((line) => ({ english_text: line, 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);
|
console.log(result);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,3 +28,6 @@
|
|||||||
<button id="close_win" (click)="onCloseClicked()"><i class="lni lni-close"></i></button>
|
<button id="close_win" (click)="onCloseClicked()"><i class="lni lni-close"></i></button>
|
||||||
</div>
|
</div>
|
||||||
<app-text-list [elements]="elements"></app-text-list>
|
<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>
|
||||||
|
|||||||
@@ -45,3 +45,14 @@
|
|||||||
min-height: calc(100vh - 2rem);
|
min-height: calc(100vh - 2rem);
|
||||||
scrollbar-color: #413738;
|
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,7 +1,8 @@
|
|||||||
import { CommonModule } from "@angular/common";
|
import { CommonModule } from "@angular/common";
|
||||||
import { Component, OnInit, ViewChild } from "@angular/core";
|
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 { 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";
|
||||||
@@ -14,7 +15,7 @@ import { parse } from "./lib/parser";
|
|||||||
templateUrl: "./nitroplus-translator.component.html",
|
templateUrl: "./nitroplus-translator.component.html",
|
||||||
styleUrl: "./nitroplus-translator.component.less",
|
styleUrl: "./nitroplus-translator.component.less",
|
||||||
})
|
})
|
||||||
export class NitroplusComponent implements OnInit {
|
export class NitroplusComponent implements OnInit, AfterViewInit {
|
||||||
title = "NitroPlusTranslator";
|
title = "NitroPlusTranslator";
|
||||||
elements: TranslateData[] = [];
|
elements: TranslateData[] = [];
|
||||||
@ViewChild("fileInput") fileInput: HTMLInputElement | null = null;
|
@ViewChild("fileInput") fileInput: HTMLInputElement | null = null;
|
||||||
@@ -36,6 +37,25 @@ export class NitroplusComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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) {
|
submitFile($event: Event) {
|
||||||
const target = $event.target as HTMLInputElement;
|
const target = $event.target as HTMLInputElement;
|
||||||
if (target.files) {
|
if (target.files) {
|
||||||
|
|||||||
Reference in New Issue
Block a user