Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 1929760e82 | |||
| 167e5c4f65 | |||
| 40c9ca38b9 | |||
| 6bb99f6e0e |
@@ -1,5 +1,5 @@
|
|||||||
import { CommonModule } from "@angular/common";
|
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 { TranslationPipe } from "../../../../pipes/translation.pipe";
|
||||||
import { NpsFile, 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";
|
||||||
@@ -11,7 +11,7 @@ import { TranslateBlockComponent } from "../translate_block/translate_block.comp
|
|||||||
standalone: true,
|
standalone: true,
|
||||||
imports: [CommonModule, TranslateBlockComponent, TranslationPipe],
|
imports: [CommonModule, TranslateBlockComponent, TranslationPipe],
|
||||||
})
|
})
|
||||||
export class TextListComponent implements OnInit {
|
export class TextListComponent implements AfterViewInit {
|
||||||
@ViewChildren("translateBlock") translate_blocks: QueryList<TranslateBlockComponent> | null =
|
@ViewChildren("translateBlock") translate_blocks: QueryList<TranslateBlockComponent> | null =
|
||||||
null;
|
null;
|
||||||
fileName = "";
|
fileName = "";
|
||||||
@@ -19,13 +19,14 @@ export class TextListComponent implements OnInit {
|
|||||||
@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));
|
||||||
|
this.ngAfterViewInit();
|
||||||
}
|
}
|
||||||
|
|
||||||
get elements() {
|
get elements() {
|
||||||
return this.elements_data;
|
return this.elements_data;
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngAfterViewInit(): void {
|
||||||
const data = localStorage.getItem("original_file");
|
const data = localStorage.getItem("original_file");
|
||||||
if (data) {
|
if (data) {
|
||||||
const file: NpsFile = JSON.parse(data);
|
const file: NpsFile = JSON.parse(data);
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
<div class="element">
|
<div class="element">
|
||||||
<h2>{{ index + 1 }}</h2>
|
<h2>{{ index + 1 }}</h2>
|
||||||
<div class="fields">
|
<div class="fields">
|
||||||
|
<h2>{{ item.name }}</h2>
|
||||||
<nwui-textarea [contenteditable]="false">{{ item.english_text }}</nwui-textarea>
|
<nwui-textarea [contenteditable]="false">{{ item.english_text }}</nwui-textarea>
|
||||||
<nwui-textarea
|
<nwui-textarea
|
||||||
#translatedText
|
#translatedText
|
||||||
|
|||||||
@@ -17,7 +17,11 @@ import { TranslateService } from "../../services/translate.service";
|
|||||||
})
|
})
|
||||||
export class TranslateBlockComponent implements OnInit {
|
export class TranslateBlockComponent implements OnInit {
|
||||||
@ViewChild("translatedText") translatedText: NWUITextAreaComponent | null = null;
|
@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;
|
@Input({ required: true }) index = 0;
|
||||||
translateLoading = false;
|
translateLoading = false;
|
||||||
isEditing = false;
|
isEditing = false;
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
export interface TranslateData {
|
export interface TranslateData {
|
||||||
english_text: string;
|
english_text: string;
|
||||||
translated_text: string;
|
translated_text: string;
|
||||||
|
name: string;
|
||||||
}
|
}
|
||||||
export interface NpsFile {
|
export interface NpsFile {
|
||||||
file_name: string;
|
file_name: string;
|
||||||
|
|||||||
@@ -3,20 +3,33 @@ import { TranslateData } from "../dto/translate_data.dto";
|
|||||||
export function parse(text: string): TranslateData[] {
|
export function parse(text: string): TranslateData[] {
|
||||||
// Find all TEXT attr data
|
// Find all TEXT attr data
|
||||||
const result: TranslateData[] = [];
|
const result: TranslateData[] = [];
|
||||||
const re = /<[^>]*TEXT="(?<textAttr>[^>"]+)"[^>]*>|<[^>]*>|\/\/.*|\s*\n\s*/gm;
|
const re = /^(?!\/\/)<[^>]*TEXT="(?<textAttr>[^>"]+)"[^>]*>/gim;
|
||||||
for (const match of text.matchAll(re)) {
|
for (const match of text.matchAll(re)) {
|
||||||
|
console.log(match);
|
||||||
if (match.groups?.["textAttr"])
|
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");
|
const name_re = /<voice name="(?<name>[^"]+)"[^>]*>(?<text>[\s\S]*?)(?=<voice|$)/gi;
|
||||||
result.push(
|
|
||||||
...replaced_text
|
for (const match of text.matchAll(name_re)) {
|
||||||
.split("\n")
|
if (match.groups?.["name"] && match.groups?.["text"]) {
|
||||||
.map((line) => line.trim())
|
const name_text = match.groups?.["text"];
|
||||||
.filter((line) => line.length > 0)
|
const name = match.groups?.["name"];
|
||||||
.map((line) => ({ english_text: line, translated_text: "" })),
|
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);
|
console.log(result);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "nwaifu-web",
|
"name": "nwaifu-web",
|
||||||
"version": "0.2.2",
|
"version": "0.2.3",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"ng": "ng",
|
"ng": "ng",
|
||||||
"start": "nx serve NwaifuWeb",
|
"start": "nx serve NwaifuWeb",
|
||||||
|
|||||||
Reference in New Issue
Block a user