Compare commits
15 Commits
feature/tr
...
dev
| Author | SHA1 | Date | |
|---|---|---|---|
| be6b2f9887 | |||
| a6876cfb0b | |||
| 69b46653e6 | |||
| 300d0baf63 | |||
| d23315e2b9 | |||
| 9680551e48 | |||
| 36f3adc1aa | |||
| 18de4fe6fd | |||
| 0108281ea9 | |||
| b2c5fc75f9 | |||
| 396ee9ab77 | |||
| 2374bfe0d3 | |||
| ab9f210fb0 | |||
| 46ec01346c | |||
| 16b6e34ed9 |
42
.eslintrc.base.json
Normal file
42
.eslintrc.base.json
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
{
|
||||||
|
"root": true,
|
||||||
|
"ignorePatterns": ["**/*"],
|
||||||
|
"plugins": ["@nx"],
|
||||||
|
"overrides": [
|
||||||
|
{
|
||||||
|
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
|
||||||
|
"rules": {
|
||||||
|
"@nx/enforce-module-boundaries": [
|
||||||
|
"error",
|
||||||
|
{
|
||||||
|
"enforceBuildableLibDependency": true,
|
||||||
|
"allow": [],
|
||||||
|
"depConstraints": [
|
||||||
|
{
|
||||||
|
"sourceTag": "*",
|
||||||
|
"onlyDependOnLibsWithTags": ["*"]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"files": ["*.ts", "*.tsx"],
|
||||||
|
"extends": ["plugin:@nx/typescript"],
|
||||||
|
"rules": {}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"files": ["*.js", "*.jsx"],
|
||||||
|
"extends": ["plugin:@nx/javascript"],
|
||||||
|
"rules": {}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"files": ["*.spec.ts", "*.spec.tsx", "*.spec.js", "*.spec.jsx"],
|
||||||
|
"env": {
|
||||||
|
"jest": true
|
||||||
|
},
|
||||||
|
"rules": {}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -1,24 +1,17 @@
|
|||||||
{
|
{
|
||||||
"root": true,
|
|
||||||
"ignorePatterns": ["!**/*"],
|
"ignorePatterns": ["!**/*"],
|
||||||
"plugins": ["@nx"],
|
|
||||||
"overrides": [
|
"overrides": [
|
||||||
{
|
{
|
||||||
"files": ["*.ts", "*.tsx"],
|
"files": ["*.ts", "*.tsx"],
|
||||||
"extends": ["plugin:@nx/typescript"],
|
|
||||||
"rules": {}
|
"rules": {}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"files": ["*.js", "*.jsx"],
|
"files": ["*.js", "*.jsx"],
|
||||||
"extends": ["plugin:@nx/javascript"],
|
|
||||||
"rules": {}
|
"rules": {}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"files": ["*.ts"],
|
"files": ["*.ts"],
|
||||||
"extends": [
|
"extends": ["plugin:@nx/angular", "plugin:@angular-eslint/template/process-inline-templates"],
|
||||||
"plugin:@nx/angular",
|
|
||||||
"plugin:@angular-eslint/template/process-inline-templates"
|
|
||||||
],
|
|
||||||
"rules": {
|
"rules": {
|
||||||
"@angular-eslint/directive-selector": [
|
"@angular-eslint/directive-selector": [
|
||||||
"error",
|
"error",
|
||||||
@@ -43,5 +36,6 @@
|
|||||||
"extends": ["plugin:@nx/angular-template"],
|
"extends": ["plugin:@nx/angular-template"],
|
||||||
"rules": {}
|
"rules": {}
|
||||||
}
|
}
|
||||||
]
|
],
|
||||||
|
"extends": ["./.eslintrc.base.json"]
|
||||||
}
|
}
|
||||||
|
|||||||
2
.gitignore
vendored
2
.gitignore
vendored
@@ -40,3 +40,5 @@ Thumbs.db
|
|||||||
|
|
||||||
.nx/cache
|
.nx/cache
|
||||||
.angular
|
.angular
|
||||||
|
|
||||||
|
*.nps
|
||||||
5
.vscode/settings.json
vendored
5
.vscode/settings.json
vendored
@@ -1,5 +1,8 @@
|
|||||||
{
|
{
|
||||||
"editor.defaultFormatter": "esbenp.prettier-vscode",
|
"editor.defaultFormatter": "esbenp.prettier-vscode",
|
||||||
"editor.formatOnSave": true,
|
"editor.formatOnSave": true,
|
||||||
"editor.tabSize": 2
|
"editor.tabSize": 2,
|
||||||
|
"cSpell.words": [
|
||||||
|
"nwui"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
23
jest.config.app.ts
Normal file
23
jest.config.app.ts
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
/* eslint-disable */
|
||||||
|
export default {
|
||||||
|
displayName: 'NitroPlusTranslator',
|
||||||
|
preset: './jest.preset.js',
|
||||||
|
setupFilesAfterEnv: ['<rootDir>/src/test-setup.ts'],
|
||||||
|
coverageDirectory: './coverage/NitroPlusTranslator',
|
||||||
|
transform: {
|
||||||
|
'^.+\\.(ts|mjs|js|html)$': [
|
||||||
|
'jest-preset-angular',
|
||||||
|
{
|
||||||
|
tsconfig: '<rootDir>/tsconfig.spec.json',
|
||||||
|
stringifyContentPathRegex: '\\.(html|svg)$',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
transformIgnorePatterns: ['node_modules/(?!.*\\.mjs$)'],
|
||||||
|
snapshotSerializers: [
|
||||||
|
'jest-preset-angular/build/serializers/no-ng-attributes',
|
||||||
|
'jest-preset-angular/build/serializers/ng-snapshot',
|
||||||
|
'jest-preset-angular/build/serializers/html-comment',
|
||||||
|
],
|
||||||
|
testMatch: ['<rootDir>/src/**/__tests__/**/*.[jt]s?(x)', '<rootDir>/src/**/*(*.)@(spec|test).[jt]s?(x)'],
|
||||||
|
};
|
||||||
@@ -1,26 +1,5 @@
|
|||||||
/* eslint-disable */
|
import { getJestProjectsAsync } from '@nx/jest';
|
||||||
export default {
|
|
||||||
displayName: 'NitroPlusTranslator',
|
export default async () => ({
|
||||||
preset: './jest.preset.js',
|
projects: await getJestProjectsAsync(),
|
||||||
setupFilesAfterEnv: ['<rootDir>/src/test-setup.ts'],
|
});
|
||||||
coverageDirectory: './coverage/NitroPlusTranslator',
|
|
||||||
transform: {
|
|
||||||
'^.+\\.(ts|mjs|js|html)$': [
|
|
||||||
'jest-preset-angular',
|
|
||||||
{
|
|
||||||
tsconfig: '<rootDir>/tsconfig.spec.json',
|
|
||||||
stringifyContentPathRegex: '\\.(html|svg)$',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
transformIgnorePatterns: ['node_modules/(?!.*\\.mjs$)'],
|
|
||||||
snapshotSerializers: [
|
|
||||||
'jest-preset-angular/build/serializers/no-ng-attributes',
|
|
||||||
'jest-preset-angular/build/serializers/ng-snapshot',
|
|
||||||
'jest-preset-angular/build/serializers/html-comment',
|
|
||||||
],
|
|
||||||
testMatch: [
|
|
||||||
'<rootDir>/src/**/__tests__/**/*.[jt]s?(x)',
|
|
||||||
'<rootDir>/src/**/*(*.)@(spec|test).[jt]s?(x)',
|
|
||||||
],
|
|
||||||
};
|
|
||||||
|
|||||||
46
nwaifu-ui/.eslintrc.json
Normal file
46
nwaifu-ui/.eslintrc.json
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
{
|
||||||
|
"extends": [
|
||||||
|
"../.eslintrc.base.json"
|
||||||
|
],
|
||||||
|
"ignorePatterns": [
|
||||||
|
"!**/*"
|
||||||
|
],
|
||||||
|
"overrides": [
|
||||||
|
{
|
||||||
|
"files": [
|
||||||
|
"*.ts"
|
||||||
|
],
|
||||||
|
"extends": [
|
||||||
|
"plugin:@nx/angular",
|
||||||
|
"plugin:@angular-eslint/template/process-inline-templates"
|
||||||
|
],
|
||||||
|
"rules": {
|
||||||
|
"@angular-eslint/directive-selector": [
|
||||||
|
"error",
|
||||||
|
{
|
||||||
|
"type": "attribute",
|
||||||
|
"prefix": "nwui",
|
||||||
|
"style": "camelCase"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"@angular-eslint/component-selector": [
|
||||||
|
"error",
|
||||||
|
{
|
||||||
|
"type": "element",
|
||||||
|
"prefix": "nwui",
|
||||||
|
"style": "kebab-case"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"files": [
|
||||||
|
"*.html"
|
||||||
|
],
|
||||||
|
"extends": [
|
||||||
|
"plugin:@nx/angular-template"
|
||||||
|
],
|
||||||
|
"rules": {}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
7
nwaifu-ui/README.md
Normal file
7
nwaifu-ui/README.md
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
# nwaifu-ui
|
||||||
|
|
||||||
|
This library was generated with [Nx](https://nx.dev).
|
||||||
|
|
||||||
|
## Running unit tests
|
||||||
|
|
||||||
|
Run `nx test nwaifu-ui` to execute the unit tests.
|
||||||
22
nwaifu-ui/jest.config.ts
Normal file
22
nwaifu-ui/jest.config.ts
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
/* eslint-disable */
|
||||||
|
export default {
|
||||||
|
displayName: 'nwaifu-ui',
|
||||||
|
preset: '../jest.preset.js',
|
||||||
|
setupFilesAfterEnv: ['<rootDir>/src/test-setup.ts'],
|
||||||
|
coverageDirectory: '../coverage/nwaifu-ui',
|
||||||
|
transform: {
|
||||||
|
'^.+\\.(ts|mjs|js|html)$': [
|
||||||
|
'jest-preset-angular',
|
||||||
|
{
|
||||||
|
tsconfig: '<rootDir>/tsconfig.spec.json',
|
||||||
|
stringifyContentPathRegex: '\\.(html|svg)$',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
transformIgnorePatterns: ['node_modules/(?!.*\\.mjs$)'],
|
||||||
|
snapshotSerializers: [
|
||||||
|
'jest-preset-angular/build/serializers/no-ng-attributes',
|
||||||
|
'jest-preset-angular/build/serializers/ng-snapshot',
|
||||||
|
'jest-preset-angular/build/serializers/html-comment',
|
||||||
|
],
|
||||||
|
};
|
||||||
9
nwaifu-ui/project.json
Normal file
9
nwaifu-ui/project.json
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"name": "nwaifu-ui",
|
||||||
|
"$schema": "../node_modules/nx/schemas/project-schema.json",
|
||||||
|
"sourceRoot": "nwaifu-ui/src",
|
||||||
|
"prefix": "nwui",
|
||||||
|
"projectType": "library",
|
||||||
|
"tags": [],
|
||||||
|
"targets": {}
|
||||||
|
}
|
||||||
1
nwaifu-ui/src/index.ts
Normal file
1
nwaifu-ui/src/index.ts
Normal file
@@ -0,0 +1 @@
|
|||||||
|
export * from './lib';
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
<button [disabled]="disabled" [type]="type"><ng-content></ng-content></button>
|
||||||
@@ -7,8 +7,17 @@ button {
|
|||||||
color: #f5f6fa;
|
color: #f5f6fa;
|
||||||
border-radius: 15px;
|
border-radius: 15px;
|
||||||
transition: ease-in-out 0.2s;
|
transition: ease-in-out 0.2s;
|
||||||
margin: 2rem;
|
width: 100%;
|
||||||
&:hover {
|
&:hover,
|
||||||
|
&:active {
|
||||||
transform: scale(1.2);
|
transform: scale(1.2);
|
||||||
}
|
}
|
||||||
|
&:disabled {
|
||||||
|
opacity: 0.5;
|
||||||
|
&:hover,
|
||||||
|
&:active {
|
||||||
|
cursor: not-allowed;
|
||||||
|
transform: scale(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
15
nwaifu-ui/src/lib/components/button/button.component.ts
Normal file
15
nwaifu-ui/src/lib/components/button/button.component.ts
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
import { CommonModule } from '@angular/common';
|
||||||
|
import { ChangeDetectionStrategy, Component, Input } from '@angular/core';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'nwui-button',
|
||||||
|
templateUrl: './button.component.html',
|
||||||
|
styleUrls: ['./button.component.scss'],
|
||||||
|
standalone: true,
|
||||||
|
imports: [CommonModule],
|
||||||
|
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||||
|
})
|
||||||
|
export class NWUIButtonComponent {
|
||||||
|
@Input() disabled = false;
|
||||||
|
@Input() type = 'button';
|
||||||
|
}
|
||||||
1
nwaifu-ui/src/lib/components/button/index.ts
Normal file
1
nwaifu-ui/src/lib/components/button/index.ts
Normal file
@@ -0,0 +1 @@
|
|||||||
|
export * from './button.component';
|
||||||
2
nwaifu-ui/src/lib/components/index.ts
Normal file
2
nwaifu-ui/src/lib/components/index.ts
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
export * from './button';
|
||||||
|
export * from './textarea';
|
||||||
1
nwaifu-ui/src/lib/components/textarea/index.ts
Normal file
1
nwaifu-ui/src/lib/components/textarea/index.ts
Normal file
@@ -0,0 +1 @@
|
|||||||
|
export * from './textarea.component';
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
<div [attr.contenteditable]="contenteditable" [className]="className" #ref (blur)="leaveFn()">
|
||||||
|
@if(!value) {
|
||||||
|
<ng-content></ng-content>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
.nwui-textarea {
|
||||||
|
border-radius: 8px;
|
||||||
|
height: auto;
|
||||||
|
color: #efdee0;
|
||||||
|
outline: none;
|
||||||
|
padding-inline: 2rem 1rem;
|
||||||
|
background-color: transparent;
|
||||||
|
border: 2px solid #e4bdc3;
|
||||||
|
font-size: 1rem;
|
||||||
|
font-weight: inherit;
|
||||||
|
min-height: 3rem;
|
||||||
|
line-height: 3rem;
|
||||||
|
&:focus {
|
||||||
|
border: 2px solid #efdee0;
|
||||||
|
}
|
||||||
|
&.disabled {
|
||||||
|
opacity: 0.5;
|
||||||
|
}
|
||||||
|
word-wrap: break-word;
|
||||||
|
}
|
||||||
35
nwaifu-ui/src/lib/components/textarea/textarea.component.ts
Normal file
35
nwaifu-ui/src/lib/components/textarea/textarea.component.ts
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
import { CommonModule } from '@angular/common';
|
||||||
|
import { AfterViewInit, Component, ElementRef, EventEmitter, Input, Output, ViewChild } from '@angular/core';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'nwui-textarea',
|
||||||
|
imports: [CommonModule],
|
||||||
|
standalone: true,
|
||||||
|
styleUrls: ['./textarea.component.scss'],
|
||||||
|
templateUrl: './textarea.component.html',
|
||||||
|
// changeDetection: ChangeDetectionStrategy.OnPush,
|
||||||
|
})
|
||||||
|
export class NWUITextAreaComponent implements AfterViewInit {
|
||||||
|
@Input() disabled = false;
|
||||||
|
@Input() value = '';
|
||||||
|
@Input() contenteditable = true;
|
||||||
|
@Output() leave = new EventEmitter<string>();
|
||||||
|
@ViewChild('ref') ref: ElementRef<HTMLDivElement> | null = null;
|
||||||
|
|
||||||
|
get className(): string {
|
||||||
|
return `nwui-textarea ${this.disabled && !this.contenteditable ? 'disabled' : ''}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
leaveFn() {
|
||||||
|
if (this.ref) {
|
||||||
|
const target = this.ref.nativeElement;
|
||||||
|
const text = target.textContent || '';
|
||||||
|
if (this.leave) this.leave.emit(text);
|
||||||
|
target.textContent = text;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ngAfterViewInit(): void {
|
||||||
|
if (this.ref && this.value) this.ref.nativeElement.textContent = this.value;
|
||||||
|
}
|
||||||
|
}
|
||||||
1
nwaifu-ui/src/lib/index.ts
Normal file
1
nwaifu-ui/src/lib/index.ts
Normal file
@@ -0,0 +1 @@
|
|||||||
|
export * from './components';
|
||||||
8
nwaifu-ui/src/test-setup.ts
Normal file
8
nwaifu-ui/src/test-setup.ts
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
// @ts-expect-error https://thymikee.github.io/jest-preset-angular/docs/getting-started/test-environment
|
||||||
|
globalThis.ngJest = {
|
||||||
|
testEnvironmentOptions: {
|
||||||
|
errorOnUnknownElements: true,
|
||||||
|
errorOnUnknownProperties: true,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
import 'jest-preset-angular/setup-jest';
|
||||||
29
nwaifu-ui/tsconfig.json
Normal file
29
nwaifu-ui/tsconfig.json
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"target": "es2022",
|
||||||
|
"useDefineForClassFields": false,
|
||||||
|
"forceConsistentCasingInFileNames": true,
|
||||||
|
"strict": true,
|
||||||
|
"noImplicitOverride": true,
|
||||||
|
"noPropertyAccessFromIndexSignature": true,
|
||||||
|
"noImplicitReturns": true,
|
||||||
|
"noFallthroughCasesInSwitch": true
|
||||||
|
},
|
||||||
|
"files": [],
|
||||||
|
"include": [],
|
||||||
|
"references": [
|
||||||
|
{
|
||||||
|
"path": "./tsconfig.lib.json"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path": "./tsconfig.spec.json"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"extends": "../tsconfig.base.json",
|
||||||
|
"angularCompilerOptions": {
|
||||||
|
"enableI18nLegacyMessageIdFormat": false,
|
||||||
|
"strictInjectionParameters": true,
|
||||||
|
"strictInputAccessModifiers": true,
|
||||||
|
"strictTemplates": true
|
||||||
|
}
|
||||||
|
}
|
||||||
12
nwaifu-ui/tsconfig.lib.json
Normal file
12
nwaifu-ui/tsconfig.lib.json
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"extends": "./tsconfig.json",
|
||||||
|
"compilerOptions": {
|
||||||
|
"outDir": "../dist/out-tsc",
|
||||||
|
"declaration": true,
|
||||||
|
"declarationMap": true,
|
||||||
|
"inlineSources": true,
|
||||||
|
"types": []
|
||||||
|
},
|
||||||
|
"exclude": ["src/**/*.spec.ts", "src/test-setup.ts", "jest.config.ts", "src/**/*.test.ts"],
|
||||||
|
"include": ["src/**/*.ts"]
|
||||||
|
}
|
||||||
11
nwaifu-ui/tsconfig.spec.json
Normal file
11
nwaifu-ui/tsconfig.spec.json
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"extends": "./tsconfig.json",
|
||||||
|
"compilerOptions": {
|
||||||
|
"outDir": "../dist/out-tsc",
|
||||||
|
"module": "commonjs",
|
||||||
|
"target": "es2016",
|
||||||
|
"types": ["jest", "node"]
|
||||||
|
},
|
||||||
|
"files": ["src/test-setup.ts"],
|
||||||
|
"include": ["jest.config.ts", "src/**/*.test.ts", "src/**/*.spec.ts", "src/**/*.d.ts"]
|
||||||
|
}
|
||||||
7
nx.json
7
nx.json
@@ -49,6 +49,13 @@
|
|||||||
"linter": "eslint",
|
"linter": "eslint",
|
||||||
"style": "scss",
|
"style": "scss",
|
||||||
"unitTestRunner": "jest"
|
"unitTestRunner": "jest"
|
||||||
|
},
|
||||||
|
"@nx/angular:library": {
|
||||||
|
"linter": "eslint",
|
||||||
|
"unitTestRunner": "jest"
|
||||||
|
},
|
||||||
|
"@nx/angular:component": {
|
||||||
|
"style": "css"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"defaultProject": "NitroPlusTranslator"
|
"defaultProject": "NitroPlusTranslator"
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@nitro-plus-translator/source",
|
"name": "@nitro-plus-translator/source",
|
||||||
"version": "0.0.0",
|
"version": "0.0.1",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "nx serve",
|
"start": "nx serve",
|
||||||
@@ -54,7 +54,8 @@
|
|||||||
"prettier": "^2.6.2",
|
"prettier": "^2.6.2",
|
||||||
"ts-jest": "^29.1.0",
|
"ts-jest": "^29.1.0",
|
||||||
"ts-node": "10.9.1",
|
"ts-node": "10.9.1",
|
||||||
"typescript": "~5.4.2"
|
"typescript": "~5.4.2",
|
||||||
|
"bun-types": "latest"
|
||||||
},
|
},
|
||||||
"nx": {
|
"nx": {
|
||||||
"includedScripts": []
|
"includedScripts": []
|
||||||
|
|||||||
@@ -80,7 +80,7 @@
|
|||||||
"executor": "@nx/jest:jest",
|
"executor": "@nx/jest:jest",
|
||||||
"outputs": ["{workspaceRoot}/coverage/{projectName}"],
|
"outputs": ["{workspaceRoot}/coverage/{projectName}"],
|
||||||
"options": {
|
"options": {
|
||||||
"jestConfig": "jest.config.ts"
|
"jestConfig": "jest.config.app.ts"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,21 @@
|
|||||||
<div class="btns">
|
<div class="btns">
|
||||||
<app-upload-btn (fileLoaded)="onFileLoaded($event)"></app-upload-btn>
|
<nwui-button (click)="fileInput.click()">
|
||||||
<app-clear-btn (clear)="onClearClicked()"></app-clear-btn>
|
<span><i class="lni lni-upload"></i> Upload</span>
|
||||||
|
<input type="file" (change)="submitFile($event)" accept=".nps" #fileInput style="display: none" />
|
||||||
|
</nwui-button>
|
||||||
|
<nwui-button (click)="onSaveClicked()">
|
||||||
|
<span><i class="lni lni-save"></i> Save</span>
|
||||||
|
</nwui-button>
|
||||||
|
@if (this.elements.length){
|
||||||
|
<nwui-button (click)="clearAllTranslations()" [disabled]="!has_translations">
|
||||||
|
<span><i class="lni lni-trash-can"></i> Clear translations</span>
|
||||||
|
</nwui-button>
|
||||||
|
<nwui-button (click)="getAllTranslations()">
|
||||||
|
<span><i class="lni lni-google"></i> Translate all</span>
|
||||||
|
</nwui-button>
|
||||||
|
<nwui-button (click)="onClearClicked()">
|
||||||
|
<span><i class="lni lni-trash-can"></i> Clear</span>
|
||||||
|
</nwui-button>
|
||||||
|
}
|
||||||
</div>
|
</div>
|
||||||
<app-text-list [elements]="elements"></app-text-list>
|
<app-text-list [elements]="elements"></app-text-list>
|
||||||
<router-outlet></router-outlet>
|
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
.btns {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
justify-content: flex-start;
|
||||||
|
align-items: center;
|
||||||
|
nwui-button {
|
||||||
|
margin: 2rem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
import { Component, OnInit } from '@angular/core';
|
import { NgIf } from '@angular/common';
|
||||||
import { RouterModule } from '@angular/router';
|
import { Component, OnInit, ViewChild } from '@angular/core';
|
||||||
import { ClearBtnComponent } from './components/clear_btn/clear_btn.component';
|
import { NWUIButtonComponent } from '@nwaifu-ui';
|
||||||
import { TextListComponent } from './components/text_list/text_list.component';
|
import { TextListComponent } from './components/text_list/text_list.component';
|
||||||
import { UploadBtnComponent } from './components/upload_btn/upload_btn.component';
|
import { LocalStorageKeys } from './consts';
|
||||||
import { TranslateData } from './dto/translate_data.dto';
|
import { NpsFile, TranslateData } from './dto/translate_data.dto';
|
||||||
|
import { saveOriginalFile } from './lib/file_tools';
|
||||||
import { parse } from './lib/parser';
|
import { parse } from './lib/parser';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
standalone: true,
|
standalone: true,
|
||||||
imports: [UploadBtnComponent, RouterModule, TextListComponent, ClearBtnComponent],
|
imports: [TextListComponent, NWUIButtonComponent, NgIf],
|
||||||
selector: 'app-root',
|
selector: 'app-root',
|
||||||
templateUrl: './app.component.html',
|
templateUrl: './app.component.html',
|
||||||
styleUrl: './app.component.scss',
|
styleUrl: './app.component.scss',
|
||||||
@@ -16,11 +16,42 @@ import { parse } from './lib/parser';
|
|||||||
export class AppComponent implements OnInit {
|
export class AppComponent implements OnInit {
|
||||||
title = 'NitroPlusTranslator';
|
title = 'NitroPlusTranslator';
|
||||||
elements: TranslateData[] = [];
|
elements: TranslateData[] = [];
|
||||||
|
@ViewChild('fileInput') fileInput: HTMLInputElement | null = null;
|
||||||
|
@ViewChild(TextListComponent) text_list: TextListComponent | null = null;
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
const data = localStorage.getItem('translations');
|
const data = localStorage.getItem(LocalStorageKeys.TRANSLATIONS);
|
||||||
if (data) {
|
if (data) {
|
||||||
this.elements = JSON.parse(data);
|
try {
|
||||||
|
this.elements = JSON.parse(data);
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e);
|
||||||
|
alert('Error while loading');
|
||||||
|
localStorage.removeItem(LocalStorageKeys.TRANSLATIONS);
|
||||||
|
this.elements = [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
submitFile($event: Event) {
|
||||||
|
const target = $event.target as HTMLInputElement;
|
||||||
|
if (target.files) {
|
||||||
|
const file = target.files[0];
|
||||||
|
if (file) {
|
||||||
|
const reader = new FileReader();
|
||||||
|
reader.onload = () => {
|
||||||
|
if (reader.result) {
|
||||||
|
this.onFileLoaded(reader.result.toString());
|
||||||
|
const original_file: NpsFile = {
|
||||||
|
file_name: file.name,
|
||||||
|
original_text: reader.result.toString(),
|
||||||
|
};
|
||||||
|
saveOriginalFile(original_file);
|
||||||
|
target.value = '';
|
||||||
|
}
|
||||||
|
};
|
||||||
|
reader.readAsText(file);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -31,5 +62,47 @@ export class AppComponent implements OnInit {
|
|||||||
|
|
||||||
onClearClicked() {
|
onClearClicked() {
|
||||||
this.elements = [];
|
this.elements = [];
|
||||||
|
localStorage.removeItem(LocalStorageKeys.TRANSLATIONS);
|
||||||
|
}
|
||||||
|
|
||||||
|
onSaveClicked() {
|
||||||
|
const original_file: NpsFile = JSON.parse(
|
||||||
|
localStorage.getItem(LocalStorageKeys.ORIGINAL_FILE) ?? '{"file_name":"", "original_text":""}',
|
||||||
|
);
|
||||||
|
if (original_file.file_name && original_file.original_text) {
|
||||||
|
const data: TranslateData[] = JSON.parse(localStorage.getItem(LocalStorageKeys.TRANSLATIONS) ?? '[]');
|
||||||
|
if (!data.length) {
|
||||||
|
alert('No data');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
original_file.translated_text = original_file.original_text;
|
||||||
|
data.forEach((el) => {
|
||||||
|
original_file.translated_text = original_file.translated_text?.replace(el.english_text, el.translated_text);
|
||||||
|
});
|
||||||
|
|
||||||
|
const element = document.createElement('a');
|
||||||
|
const file = new Blob([original_file.translated_text], { type: 'text/plain' });
|
||||||
|
element.href = URL.createObjectURL(file);
|
||||||
|
element.download = original_file.file_name;
|
||||||
|
element.click();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//TODO: Dialog windows for clear op
|
||||||
|
clearAllTranslations() {
|
||||||
|
if (this.text_list)
|
||||||
|
if (this.text_list.translate_blocks) {
|
||||||
|
this.text_list.translate_blocks.filter((item) => item.item.translated_text).forEach((item) => item.clear());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
getAllTranslations() {
|
||||||
|
if (this.text_list)
|
||||||
|
if (this.text_list.translate_blocks)
|
||||||
|
this.text_list.translate_blocks.forEach((item) => item.sendToGoogleTranslate());
|
||||||
|
}
|
||||||
|
|
||||||
|
get has_translations(): boolean {
|
||||||
|
return this.elements.some((i) => i.translated_text);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
import { provideHttpClient } from '@angular/common/http';
|
import { provideHttpClient } from '@angular/common/http';
|
||||||
import { ApplicationConfig } from '@angular/core';
|
import { ApplicationConfig } from '@angular/core';
|
||||||
import { provideRouter } from '@angular/router';
|
|
||||||
import { appRoutes } from './app.routes';
|
|
||||||
|
|
||||||
export const appConfig: ApplicationConfig = {
|
export const appConfig: ApplicationConfig = {
|
||||||
providers: [provideHttpClient(), provideRouter(appRoutes)],
|
providers: [provideHttpClient()],
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,3 +0,0 @@
|
|||||||
<button (click)="clear_func()">
|
|
||||||
<span><i class="lni lni-trash-can"></i> Clear</span>
|
|
||||||
</button>
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
button {
|
|
||||||
outline: none;
|
|
||||||
border: none;
|
|
||||||
cursor: pointer;
|
|
||||||
background-color: #5b3f45;
|
|
||||||
padding: 1em 1.5em;
|
|
||||||
color: #f5f6fa;
|
|
||||||
border-radius: 15px;
|
|
||||||
transition: ease-in-out 0.2s;
|
|
||||||
margin: 2rem;
|
|
||||||
&:hover {
|
|
||||||
transform: scale(1.2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
import { CommonModule } from '@angular/common';
|
|
||||||
import { Component, EventEmitter, Output } from '@angular/core';
|
|
||||||
|
|
||||||
@Component({
|
|
||||||
selector: 'app-clear-btn',
|
|
||||||
templateUrl: './clear_btn.component.html',
|
|
||||||
styleUrls: ['./clear_btn.component.scss'],
|
|
||||||
standalone: true,
|
|
||||||
imports: [CommonModule],
|
|
||||||
})
|
|
||||||
export class ClearBtnComponent {
|
|
||||||
@Output() clear = new EventEmitter();
|
|
||||||
clear_func() {
|
|
||||||
localStorage.setItem('translations', '[]');
|
|
||||||
this.clear.emit();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,21 +1,6 @@
|
|||||||
<h1 *ngIf="elements_data.length">Всего: {{ elements_data.length }}</h1>
|
<h1 *ngIf="elements_data.length">Всего: {{ elements_data.length }}</h1>
|
||||||
<div id="elements">
|
<div id="elements">
|
||||||
@for(item of elements_data; track $index) {
|
@for(item of elements_data; track $index) {
|
||||||
<app-translate-block [index]="$index" [item]="item"></app-translate-block>
|
<app-translate-block #translateBlock [index]="$index" [item]="item"></app-translate-block>
|
||||||
<!-- <div class="element">
|
|
||||||
<h2>{{ $index + 1 }}</h2>
|
|
||||||
<div class="fields">
|
|
||||||
<div class="english-text">{{ item.english_text }}</div>
|
|
||||||
<div class="translated-text">
|
|
||||||
<textarea
|
|
||||||
type="text"
|
|
||||||
[value]="item.translated_text"
|
|
||||||
(change)="typeTranslation($event, $index)"
|
|
||||||
rows="1"
|
|
||||||
></textarea>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<button class="send-translate-btn" (click)="sendToTranslate(item.english_text, $index)">Translate</button>
|
|
||||||
</div> -->
|
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { CommonModule } from '@angular/common';
|
import { CommonModule } from '@angular/common';
|
||||||
import { Component, Input } from '@angular/core';
|
import { Component, Input, QueryList, ViewChildren } from '@angular/core';
|
||||||
import { TranslateData } from 'src/app/dto/translate_data.dto';
|
import { TranslateData } from '../../dto/translate_data.dto';
|
||||||
import { TranslateBlockComponent } from '../translate_block/translate_block.component';
|
import { TranslateBlockComponent } from '../translate_block/translate_block.component';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
@@ -11,6 +11,7 @@ import { TranslateBlockComponent } from '../translate_block/translate_block.comp
|
|||||||
imports: [CommonModule, TranslateBlockComponent],
|
imports: [CommonModule, TranslateBlockComponent],
|
||||||
})
|
})
|
||||||
export class TextListComponent {
|
export class TextListComponent {
|
||||||
|
@ViewChildren('translateBlock') translate_blocks: QueryList<TranslateBlockComponent> | null = null;
|
||||||
elements_data: TranslateData[] = [];
|
elements_data: TranslateData[] = [];
|
||||||
@Input() set elements(el: TranslateData[]) {
|
@Input() set elements(el: TranslateData[]) {
|
||||||
this.elements_data = el;
|
this.elements_data = el;
|
||||||
|
|||||||
@@ -1,14 +1,18 @@
|
|||||||
<div class="element">
|
<div class="element">
|
||||||
<h2>{{ index + 1 }}</h2>
|
<h2>{{ index + 1 }}</h2>
|
||||||
<div class="fields">
|
<div class="fields">
|
||||||
<div class="english-text">{{ item.english_text }}</div>
|
<nwui-textarea [contenteditable]="false">{{ item.english_text }}</nwui-textarea>
|
||||||
<div class="translated-text" #translatedText [attr.contenteditable]="isEditing" (blur)="saveTranslate()"></div>
|
<nwui-textarea
|
||||||
|
#translatedText
|
||||||
|
[contenteditable]="isEditing"
|
||||||
|
(leave)="saveTranslate($event)"
|
||||||
|
[disabled]="!isEditing"
|
||||||
|
>{{ item.translated_text }}</nwui-textarea
|
||||||
|
>
|
||||||
</div>
|
</div>
|
||||||
<div class="btns">
|
<div class="btns">
|
||||||
<button class="send-translate-btn btn" (click)="sendToGoogleTranslate()">Google</button>
|
<nwui-button (click)="sendToGoogleTranslate()" [disabled]="translateLoading">Translate</nwui-button>
|
||||||
<button class="send-translate-btn btn" (click)="sendToDeeplTranslate()">Deepl</button>
|
<nwui-button (click)="isEditing = !isEditing" [disabled]="isEditing">Edit</nwui-button>
|
||||||
<button class="send-translate-btn btn" (click)="sendToPromptTranslate()">PROMPT</button>
|
<nwui-button (click)="clear()" [disabled]="!item.translated_text.length">Clear</nwui-button>
|
||||||
<button class="change-edit-btn btn" (click)="isEditing = !isEditing" [disabled]="isEditing">Edit</button>
|
|
||||||
<button class="clear-btn btn" (click)="clear()" [disabled]="!item.translated_text.length">Clear</button>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,34 +1,3 @@
|
|||||||
.translated-text {
|
|
||||||
border-radius: 8px;
|
|
||||||
height: auto;
|
|
||||||
color: #efdee0;
|
|
||||||
outline: none;
|
|
||||||
padding-inline: 2rem 1rem;
|
|
||||||
background-color: transparent;
|
|
||||||
border: 2px solid #e4bdc3;
|
|
||||||
font-size: 1rem;
|
|
||||||
font-weight: inherit;
|
|
||||||
min-height: 3rem;
|
|
||||||
line-height: 3rem;
|
|
||||||
&:focus {
|
|
||||||
border: 2px solid #efdee0;
|
|
||||||
}
|
|
||||||
&:read-only {
|
|
||||||
opacity: 0.5;
|
|
||||||
}
|
|
||||||
word-wrap: break-word;
|
|
||||||
}
|
|
||||||
|
|
||||||
.english-text {
|
|
||||||
color: #efdee0;
|
|
||||||
border: 2px solid #e4bdc3;
|
|
||||||
word-wrap: break-word;
|
|
||||||
border-radius: 8px;
|
|
||||||
padding-inline: 2rem 1rem;
|
|
||||||
line-height: 3rem;
|
|
||||||
background-color: transparent;
|
|
||||||
}
|
|
||||||
|
|
||||||
.element {
|
.element {
|
||||||
display: flex;
|
display: flex;
|
||||||
background-color: #413738;
|
background-color: #413738;
|
||||||
@@ -62,24 +31,9 @@
|
|||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
gap: 1rem;
|
gap: 1rem;
|
||||||
.btn {
|
align-items: center;
|
||||||
outline: none;
|
padding-inline: 1rem;
|
||||||
border: none;
|
nwui-button {
|
||||||
cursor: pointer;
|
width: 100%;
|
||||||
background-color: #5b3f45;
|
|
||||||
padding: 1em 1.5em;
|
|
||||||
color: #f5f6fa;
|
|
||||||
border-radius: 15px;
|
|
||||||
transition: ease-in-out 0.2s;
|
|
||||||
&:hover {
|
|
||||||
transform: scale(1.2);
|
|
||||||
}
|
|
||||||
&:disabled {
|
|
||||||
opacity: 0.5;
|
|
||||||
&:hover {
|
|
||||||
cursor: not-allowed;
|
|
||||||
transform: scale(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,25 +1,28 @@
|
|||||||
import { CommonModule } from '@angular/common';
|
import { CommonModule } from '@angular/common';
|
||||||
import { AfterViewInit, Component, ElementRef, Input, OnInit, ViewChild } from '@angular/core';
|
import { Component, Input, OnInit, ViewChild } from '@angular/core';
|
||||||
import { TranslateData } from 'src/app/dto/translate_data.dto';
|
import { NWUIButtonComponent, NWUITextAreaComponent } from '@nwaifu-ui';
|
||||||
import { ETranslateService } from 'src/app/services/translate.enums';
|
import { LocalStorageKeys } from '../../consts';
|
||||||
import { TranslateService } from 'src/app/services/translate.service';
|
import { TranslateData } from '../../dto/translate_data.dto';
|
||||||
|
import { ETranslateService } from '../../services/translate.enums';
|
||||||
|
import { TranslateService } from '../../services/translate.service';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-translate-block',
|
selector: 'app-translate-block',
|
||||||
templateUrl: './translate_block.component.html',
|
templateUrl: './translate_block.component.html',
|
||||||
styleUrls: ['./translate_block.component.scss'],
|
styleUrls: ['./translate_block.component.scss'],
|
||||||
standalone: true,
|
standalone: true,
|
||||||
imports: [CommonModule],
|
imports: [CommonModule, NWUIButtonComponent, NWUITextAreaComponent],
|
||||||
providers: [TranslateService],
|
providers: [TranslateService],
|
||||||
})
|
})
|
||||||
export class TranslateBlockComponent implements OnInit, AfterViewInit {
|
export class TranslateBlockComponent implements OnInit {
|
||||||
@ViewChild('translatedText') translatedText: ElementRef<HTMLDivElement> | null = null;
|
@ViewChild('translatedText') translatedText: NWUITextAreaComponent | null = null;
|
||||||
@Input() item: TranslateData = { english_text: '', translated_text: '' };
|
@Input({ required: true }) item: TranslateData = { english_text: '', translated_text: '' };
|
||||||
@Input() index = 0;
|
@Input({ required: true }) index = 0;
|
||||||
|
translateLoading = false;
|
||||||
isEditing = false;
|
isEditing = false;
|
||||||
|
|
||||||
saveChanges() {
|
saveChanges() {
|
||||||
const data: TranslateData[] = JSON.parse(localStorage.getItem('translations') ?? '[]');
|
const data: TranslateData[] = JSON.parse(localStorage.getItem(LocalStorageKeys.TRANSLATIONS) ?? '[]');
|
||||||
if (!data.length) {
|
if (!data.length) {
|
||||||
alert('No data');
|
alert('No data');
|
||||||
return;
|
return;
|
||||||
@@ -33,11 +36,14 @@ export class TranslateBlockComponent implements OnInit, AfterViewInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
constructor(private translateService: TranslateService) {}
|
constructor(private translateService: TranslateService) {}
|
||||||
|
|
||||||
private sendToTranslate(service: ETranslateService = ETranslateService.GOOGLE) {
|
private sendToTranslate(service: ETranslateService = ETranslateService.GOOGLE) {
|
||||||
|
this.translateLoading = true;
|
||||||
this.translateService.translate(this.item.english_text, service).subscribe((text) => {
|
this.translateService.translate(this.item.english_text, service).subscribe((text) => {
|
||||||
|
if (this.translatedText) if (this.translatedText.ref) this.translatedText.ref.nativeElement.textContent = text;
|
||||||
this.item.translated_text = text;
|
this.item.translated_text = text;
|
||||||
if (this.translatedText) this.translatedText.nativeElement.textContent = text;
|
|
||||||
this.isEditing = false;
|
this.isEditing = false;
|
||||||
|
this.translateLoading = false;
|
||||||
this.saveChanges();
|
this.saveChanges();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -54,23 +60,16 @@ export class TranslateBlockComponent implements OnInit, AfterViewInit {
|
|||||||
this.sendToTranslate(ETranslateService.PROMPT);
|
this.sendToTranslate(ETranslateService.PROMPT);
|
||||||
}
|
}
|
||||||
|
|
||||||
saveTranslate() {
|
saveTranslate(text: string) {
|
||||||
this.isEditing = false;
|
this.isEditing = false;
|
||||||
if (this.translatedText) {
|
if (this.translatedText) if (this.translatedText.ref) this.translatedText.ref.nativeElement.textContent = '';
|
||||||
this.item.translated_text = this.translatedText.nativeElement.textContent || '';
|
this.item.translated_text = text;
|
||||||
this.translatedText.nativeElement.textContent = '';
|
|
||||||
this.translatedText.nativeElement.textContent = this.item.translated_text;
|
|
||||||
}
|
|
||||||
this.saveChanges();
|
this.saveChanges();
|
||||||
}
|
}
|
||||||
clear() {
|
clear() {
|
||||||
this.item.translated_text = '';
|
this.item.translated_text = '';
|
||||||
if (this.translatedText) this.translatedText.nativeElement.textContent = '';
|
|
||||||
this.isEditing = true;
|
this.isEditing = true;
|
||||||
|
if (this.translatedText) if (this.translatedText.ref) this.translatedText.ref.nativeElement.textContent = '';
|
||||||
this.saveChanges();
|
this.saveChanges();
|
||||||
}
|
}
|
||||||
|
|
||||||
ngAfterViewInit(): void {
|
|
||||||
if (this.translatedText) this.translatedText.nativeElement.textContent = this.item.translated_text;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +0,0 @@
|
|||||||
<button (click)="fileInput.click()">
|
|
||||||
<span><i class="lni lni-upload"></i> Upload</span>
|
|
||||||
<input type="file" (change)="onChange($event)" #fileInput style="display: none" />
|
|
||||||
</button>
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
import { CommonModule } from '@angular/common';
|
|
||||||
import { Component, ElementRef, EventEmitter, Output, ViewChild } from '@angular/core';
|
|
||||||
|
|
||||||
@Component({
|
|
||||||
imports: [CommonModule],
|
|
||||||
selector: 'app-upload-btn',
|
|
||||||
styleUrl: './upload_btn.component.scss',
|
|
||||||
templateUrl: './upload_btn.component.html',
|
|
||||||
standalone: true,
|
|
||||||
})
|
|
||||||
export class UploadBtnComponent {
|
|
||||||
@ViewChild('fileInput') fileInput: ElementRef<HTMLDivElement> | null = null;
|
|
||||||
@Output() fileLoaded = new EventEmitter<string>();
|
|
||||||
|
|
||||||
onChange(event: Event) {
|
|
||||||
if (event.target) {
|
|
||||||
const target = event.target as HTMLInputElement;
|
|
||||||
if (target.files) {
|
|
||||||
const file: File = target.files[0];
|
|
||||||
if (!file.name.endsWith('.nps')) {
|
|
||||||
alert('Only .nps files are allowed');
|
|
||||||
target.value = '';
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const reader = new FileReader();
|
|
||||||
reader.onload = () => {
|
|
||||||
this.fileLoaded.emit(reader.result as string);
|
|
||||||
target.value = '';
|
|
||||||
};
|
|
||||||
reader.readAsText(file);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
4
src/app/consts.ts
Normal file
4
src/app/consts.ts
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
export enum LocalStorageKeys {
|
||||||
|
TRANSLATIONS = 'translations',
|
||||||
|
ORIGINAL_FILE = 'original_file',
|
||||||
|
}
|
||||||
@@ -2,3 +2,8 @@ export interface TranslateData {
|
|||||||
english_text: string;
|
english_text: string;
|
||||||
translated_text: string;
|
translated_text: string;
|
||||||
}
|
}
|
||||||
|
export interface NpsFile {
|
||||||
|
file_name: string;
|
||||||
|
original_text: string;
|
||||||
|
translated_text?: string;
|
||||||
|
}
|
||||||
|
|||||||
6
src/app/lib/file_tools.ts
Normal file
6
src/app/lib/file_tools.ts
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
import { LocalStorageKeys } from '../consts';
|
||||||
|
import { NpsFile } from '../dto/translate_data.dto';
|
||||||
|
|
||||||
|
export function saveOriginalFile(file: NpsFile) {
|
||||||
|
localStorage.setItem(LocalStorageKeys.ORIGINAL_FILE, JSON.stringify(file));
|
||||||
|
}
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
import { Pipe, PipeTransform } from '@angular/core';
|
|
||||||
import { TranslateService } from '../services/translate.service';
|
|
||||||
|
|
||||||
@Pipe({ name: 'translate', standalone: true, pure: false })
|
|
||||||
export class TranslatePipe implements PipeTransform {
|
|
||||||
constructor(private translateService: TranslateService) {}
|
|
||||||
transform(text: string) {
|
|
||||||
return this.translateService.translate(text);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
30
tsconfig.base.json
Normal file
30
tsconfig.base.json
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
{
|
||||||
|
"compileOnSave": false,
|
||||||
|
"compilerOptions": {
|
||||||
|
"rootDir": ".",
|
||||||
|
"sourceMap": true,
|
||||||
|
"declaration": false,
|
||||||
|
"moduleResolution": "node",
|
||||||
|
"emitDecoratorMetadata": true,
|
||||||
|
"experimentalDecorators": true,
|
||||||
|
"importHelpers": true,
|
||||||
|
"target": "es2022",
|
||||||
|
"module": "esnext",
|
||||||
|
"lib": [
|
||||||
|
"es2020",
|
||||||
|
"dom"
|
||||||
|
],
|
||||||
|
"skipLibCheck": true,
|
||||||
|
"skipDefaultLibCheck": true,
|
||||||
|
"baseUrl": ".",
|
||||||
|
"paths": {
|
||||||
|
"@nwaifu-ui": [
|
||||||
|
"nwaifu-ui/src/index.ts"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"exclude": [
|
||||||
|
"node_modules",
|
||||||
|
"tmp"
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -1,22 +1,5 @@
|
|||||||
{
|
{
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"rootDir": ".",
|
|
||||||
"sourceMap": true,
|
|
||||||
"declaration": false,
|
|
||||||
"moduleResolution": "node",
|
|
||||||
"emitDecoratorMetadata": true,
|
|
||||||
"experimentalDecorators": true,
|
|
||||||
"importHelpers": true,
|
|
||||||
"target": "es2022",
|
|
||||||
"module": "esnext",
|
|
||||||
"lib": [
|
|
||||||
"es2020",
|
|
||||||
"dom"
|
|
||||||
],
|
|
||||||
"skipLibCheck": true,
|
|
||||||
"skipDefaultLibCheck": true,
|
|
||||||
"baseUrl": ".",
|
|
||||||
"paths": {},
|
|
||||||
"useDefineForClassFields": false,
|
"useDefineForClassFields": false,
|
||||||
"forceConsistentCasingInFileNames": true,
|
"forceConsistentCasingInFileNames": true,
|
||||||
"strict": true,
|
"strict": true,
|
||||||
@@ -38,15 +21,11 @@
|
|||||||
"path": "./tsconfig.spec.json"
|
"path": "./tsconfig.spec.json"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"compileOnSave": false,
|
|
||||||
"exclude": [
|
|
||||||
"node_modules",
|
|
||||||
"tmp"
|
|
||||||
],
|
|
||||||
"angularCompilerOptions": {
|
"angularCompilerOptions": {
|
||||||
"enableI18nLegacyMessageIdFormat": false,
|
"enableI18nLegacyMessageIdFormat": false,
|
||||||
"strictInjectionParameters": true,
|
"strictInjectionParameters": true,
|
||||||
"strictInputAccessModifiers": true,
|
"strictInputAccessModifiers": true,
|
||||||
"strictTemplates": true
|
"strictTemplates": true
|
||||||
}
|
},
|
||||||
}
|
"extends": "./tsconfig.base.json"
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user