Compare commits
5 Commits
c508caab7b
...
v0.2.3
| Author | SHA1 | Date | |
|---|---|---|---|
| 1929760e82 | |||
| 167e5c4f65 | |||
| 40c9ca38b9 | |||
| 6bb99f6e0e | |||
| 53fee00315 |
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
export interface TranslateData {
|
||||
english_text: string;
|
||||
translated_text: string;
|
||||
name: string;
|
||||
}
|
||||
export interface NpsFile {
|
||||
file_name: string;
|
||||
|
||||
@@ -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())
|
||||
.filter((line) => line.length > 0)
|
||||
.map((line) => ({ english_text: line, translated_text: "" })),
|
||||
);
|
||||
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) => line.trim())
|
||||
.forEach((line) => {
|
||||
result.push({ english_text: line, translated_text: "", name: name });
|
||||
});
|
||||
}
|
||||
}
|
||||
console.log(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "nwaifu-web",
|
||||
"version": "0.0.1",
|
||||
"version": "0.2.3",
|
||||
"scripts": {
|
||||
"ng": "ng",
|
||||
"start": "nx serve NwaifuWeb",
|
||||
|
||||
Reference in New Issue
Block a user