Merge branch 'fix/regex' into dev
This commit is contained in:
@@ -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>
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user