4 Commits

6 changed files with 35 additions and 15 deletions

View File

@@ -1,5 +1,5 @@
import { CommonModule } from "@angular/common";
import { Component, Input, OnInit, QueryList, ViewChildren } from "@angular/core";
import { AfterViewInit, Component, Input, QueryList, ViewChildren } from "@angular/core";
import { TranslationPipe } from "../../../../pipes/translation.pipe";
import { NpsFile, TranslateData } from "../../dto/translate_data.dto";
import { TranslateBlockComponent } from "../translate_block/translate_block.component";
@@ -11,7 +11,7 @@ import { TranslateBlockComponent } from "../translate_block/translate_block.comp
standalone: true,
imports: [CommonModule, TranslateBlockComponent, TranslationPipe],
})
export class TextListComponent implements OnInit {
export class TextListComponent implements AfterViewInit {
@ViewChildren("translateBlock") translate_blocks: QueryList<TranslateBlockComponent> | null =
null;
fileName = "";
@@ -19,13 +19,14 @@ export class TextListComponent implements OnInit {
@Input() set elements(el: TranslateData[]) {
this.elements_data = el;
localStorage.setItem("translations", JSON.stringify(this.elements_data));
this.ngAfterViewInit();
}
get elements() {
return this.elements_data;
}
ngOnInit(): void {
ngAfterViewInit(): void {
const data = localStorage.getItem("original_file");
if (data) {
const file: NpsFile = JSON.parse(data);

View File

@@ -1,6 +1,7 @@
<div class="element">
<h2>{{ index + 1 }}</h2>
<div class="fields">
<h2>{{ item.name }}</h2>
<nwui-textarea [contenteditable]="false">{{ item.english_text }}</nwui-textarea>
<nwui-textarea
#translatedText

View File

@@ -17,7 +17,11 @@ import { TranslateService } from "../../services/translate.service";
})
export class TranslateBlockComponent implements OnInit {
@ViewChild("translatedText") translatedText: NWUITextAreaComponent | null = null;
@Input({ required: true }) item: TranslateData = { english_text: "", translated_text: "" };
@Input({ required: true }) item: TranslateData = {
english_text: "",
translated_text: "",
name: "",
};
@Input({ required: true }) index = 0;
translateLoading = false;
isEditing = false;

View File

@@ -1,6 +1,7 @@
export interface TranslateData {
english_text: string;
translated_text: string;
name: string;
}
export interface NpsFile {
file_name: string;

View File

@@ -3,20 +3,33 @@ import { TranslateData } from "../dto/translate_data.dto";
export function parse(text: string): TranslateData[] {
// Find all TEXT attr data
const result: TranslateData[] = [];
const re = /<[^>]*TEXT="(?<textAttr>[^>"]+)"[^>]*>|<[^>]*>|\/\/.*|\s*\n\s*/gm;
const re = /^(?!\/\/)<[^>]*TEXT="(?<textAttr>[^>"]+)"[^>]*>/gim;
for (const match of text.matchAll(re)) {
console.log(match);
if (match.groups?.["textAttr"])
result.push({ english_text: match.groups?.["textAttr"], translated_text: "" });
result.push({
english_text: match.groups?.["textAttr"],
translated_text: "",
name: "Choice (without name)",
});
}
const replaced_text = text.replace(re, "\n").replace(/\s*\n\s*/gm, "\n");
result.push(
...replaced_text
.split("\n")
.map((line) => line.trim())
const name_re = /<voice name="(?<name>[^"]+)"[^>]*>(?<text>[\s\S]*?)(?=<voice|$)/gi;
for (const match of text.matchAll(name_re)) {
if (match.groups?.["name"] && match.groups?.["text"]) {
const name_text = match.groups?.["text"];
const name = match.groups?.["name"];
const re = /<[^>]*>|\/\/.*|\s*\n\s*/gm;
name_text
.split(re)
.filter((line) => line.length > 0)
.map((line) => ({ english_text: line, translated_text: "" })),
);
.map((line) => line.trim())
.forEach((line) => {
result.push({ english_text: line, translated_text: "", name: name });
});
}
}
console.log(result);
return result;
}

View File

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