Skip to content

Commit

Permalink
- Allow empty translations
Browse files Browse the repository at this point in the history
- Strip empty target blocks if state is initial
  • Loading branch information
u241519 committed Dec 13, 2024
1 parent 6d61b62 commit 27f76d1
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 66 deletions.
101 changes: 51 additions & 50 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,68 +47,68 @@
"!tsconfig.json"
],
"dependencies": {
"@nestjs/common": "^10.2.0",
"@nestjs/core": "^10.2.0",
"@nestjs/platform-express": "^10.2.0",
"@nestjs/platform-ws": "^10.2.0",
"@nestjs/serve-static": "^4.0.0",
"@nestjs/websockets": "^10.2.0",
"@xmldom/xmldom": "^0.8.10",
"@nestjs/common": "^10.4.15",
"@nestjs/core": "^10.4.15",
"@nestjs/platform-express": "^10.4.15",
"@nestjs/platform-ws": "^10.4.15",
"@nestjs/serve-static": "^4.0.2",
"@nestjs/websockets": "^10.4.15",
"@xmldom/xmldom": "^0.9.6",
"class-transformer": "^0.5.1",
"class-validator": "^0.14.0",
"class-validator": "^0.14.1",
"js-levenshtein": "^1.1.6",
"reflect-metadata": "^0.2.2",
"rxjs": "~7.8.1"
},
"devDependencies": {
"@angular-devkit/build-angular": "^19.0.1",
"@angular-eslint/builder": "19.0.0-alpha.1",
"@angular-eslint/eslint-plugin": "19.0.0-alpha.1",
"@angular-eslint/eslint-plugin-template": "19.0.0-alpha.1",
"@angular-eslint/schematics": "19.0.0-alpha.1",
"@angular-eslint/template-parser": "19.0.0-alpha.1",
"@angular/animations": "^19.0.0",
"@angular/cdk": "^19.0.0",
"@angular/cli": "^19.0.1",
"@angular/common": "^19.0.0",
"@angular/compiler": "^19.0.0",
"@angular/compiler-cli": "^19.0.0",
"@angular/core": "^19.0.0",
"@angular/forms": "^19.0.0",
"@angular/language-service": "^19.0.0",
"@angular/localize": "^19.0.0",
"@angular/material": "^19.0.0",
"@angular/platform-browser": "^19.0.0",
"@angular/platform-browser-dynamic": "^19.0.0",
"@angular/router": "^19.0.0",
"@nestjs/schematics": "^10.0.0",
"@nestjs/testing": "^10.2.0",
"@types/express": "^4.17.20",
"@types/jasmine": "~5.1.1",
"@types/jest": "^29.5.7",
"@types/js-levenshtein": "^1.1.2",
"@types/node": "^18.16.3",
"@types/ws": "^8.5.8",
"@typescript-eslint/eslint-plugin": "^7.2.0",
"@typescript-eslint/parser": "^7.2.0",
"@angular-devkit/build-angular": "^19.0.5",
"@angular-eslint/builder": "19.0.2",
"@angular-eslint/eslint-plugin": "19.0.2",
"@angular-eslint/eslint-plugin-template": "19.0.2",
"@angular-eslint/schematics": "19.0.2",
"@angular-eslint/template-parser": "19.0.2",
"@angular/animations": "^19.0.4",
"@angular/cdk": "^19.0.3",
"@angular/cli": "^19.0.5",
"@angular/common": "^19.0.4",
"@angular/compiler": "^19.0.4",
"@angular/compiler-cli": "^19.0.4",
"@angular/core": "^19.0.4",
"@angular/forms": "^19.0.4",
"@angular/language-service": "^19.0.4",
"@angular/localize": "^19.0.4",
"@angular/material": "^19.0.3",
"@angular/platform-browser": "^19.0.4",
"@angular/platform-browser-dynamic": "^19.0.4",
"@angular/router": "^19.0.4",
"@nestjs/schematics": "^10.2.3",
"@nestjs/testing": "^10.4.15",
"@types/express": "^5.0.0",
"@types/jasmine": "~5.1.5",
"@types/jest": "^29.5.14",
"@types/js-levenshtein": "^1.1.3",
"@types/node": "^22.10.2",
"@types/ws": "^8.5.13",
"@typescript-eslint/eslint-plugin": "^8.18.0",
"@typescript-eslint/parser": "^8.18.0",
"commit-and-tag-version": "^12.5.0",
"eslint": "^8.57.0",
"eslint-plugin-import": "^2.29.0",
"husky": "^9.0.11",
"jasmine-core": "~5.1.1",
"eslint": "^9.16.0",
"eslint-plugin-import": "^2.31.0",
"husky": "^9.1.7",
"jasmine-core": "~5.5.0",
"jest": "^29.7.0",
"karma": "~6.4.2",
"karma": "~6.4.4",
"karma-chrome-launcher": "~3.2.0",
"karma-coverage": "~2.2.1",
"karma-jasmine": "~5.1.0",
"karma-jasmine-html-reporter": "~2.1.0",
"lint-staged": "^15.0.2",
"prettier": "^3.0.3",
"rimraf": "^5.0.5",
"rollup": "^4.3.0",
"lint-staged": "^15.2.11",
"prettier": "^3.4.2",
"rimraf": "^6.0.1",
"rollup": "^4.28.1",
"rollup-plugin-ts": "^3.4.5",
"ts-jest": "^29.1.1",
"ts-node": "^10.4.0",
"ts-jest": "^29.2.5",
"ts-node": "^10.9.2",
"tsconfig-paths": "^4.2.0",
"tslib": "^2.8.1",
"typescript": "~5.6.3",
Expand Down Expand Up @@ -153,5 +153,6 @@
"*.{js,ts,css,scss,json,md,html}": [
"prettier --write --ignore-unknown"
]
}
},
"packageManager": "[email protected]+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
}
6 changes: 5 additions & 1 deletion server/deserialization/xlf2-deserializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,11 @@ export class Xlf2Deserializer extends XlfDeserializerBase {
}

private _extractTarget(segment: Element) {
return this._convertToString(segment.getElementsByTagName('target')[0]);
const node = segment.getElementsByTagName('target')[0];
if (!node) {
return '';
}
return this._convertToString(node);
}

private _extractNote(notes: Element, category: string): string[] {
Expand Down
6 changes: 5 additions & 1 deletion server/serialization/xlf2-serializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ ${units
}
<segment state="${u.state}">
<source>${u.source}</source>
<target>${u.target}</target>
${
u.state === 'initial' && (!u.target || u.target === '')
? `` // Don't include target if it is "initial" and empty
: `<target>${u.target}</target>`
}
</segment>
</unit>`,
)
Expand Down
4 changes: 1 addition & 3 deletions src/app/target/core/translation-target.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,7 @@ export class TranslationTargetService {
}

updateUnit(unit: Partial<TranslationTargetUnitResponse>) {
if (unit.target === '' && unit.state !== 'initial') {
unit.state = 'initial';
} else if (unit.target !== '' && unit.state === 'initial') {
if (unit.target !== '' && unit.state === 'initial') {
unit.state = 'translated';
}

Expand Down
2 changes: 1 addition & 1 deletion src/app/target/translate/translate-datasource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export class TranslateDataSource extends TranslationDataSource<
const unit: FormTargetUnit = {
...u,
target: new UntypedFormControl(u.target),
state: new UntypedFormControl({ value: u.state, disabled: !u.target }),
state: new UntypedFormControl(u.state),
};
this._translationTargetService.updateUnitOnChange(u, unit, this._destroy);
unit.target.markAsTouched();
Expand Down
6 changes: 2 additions & 4 deletions src/app/target/translate/translate.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@
<td mat-cell *matCellDef="let row">
<mat-form-field>
<mat-select [formControl]="row.state">
<mat-option *ngIf="row.state.value === 'initial'" value="initial" i18n
>Initial</mat-option
>
<mat-option value="initial" i18n>Initial</mat-option>
<mat-option value="translated" i18n>Translated</mat-option>
<mat-option value="reviewed" i18n>Reviewed</mat-option>
<mat-option value="final" i18n>Final</mat-option>
Expand Down Expand Up @@ -132,7 +130,7 @@
'source-filter',
'target-filter',
'state-filter',
'action'
'action',
];
sticky: true
"
Expand Down
3 changes: 1 addition & 2 deletions src/app/target/translate/translate.component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { TextFieldModule } from '@angular/cdk/text-field';
import { NgIf, AsyncPipe } from '@angular/common';
import { AsyncPipe } from '@angular/common';
import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core';
import { UntypedFormBuilder, ReactiveFormsModule } from '@angular/forms';
import { MatButtonModule } from '@angular/material/button';
Expand Down Expand Up @@ -33,7 +33,6 @@ import { TranslateDataSource } from './translate-datasource';
TextFieldModule,
ReactiveFormsModule,
MatSelectModule,
NgIf,
MatOptionModule,
MatButtonModule,
RouterLink,
Expand Down
4 changes: 1 addition & 3 deletions src/app/target/unit/unit.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ <h2>{{ (unit | async)?.id }}</h2>
<mat-form-field>
<mat-label>State</mat-label>
<mat-select formControlName="state">
<mat-option *ngIf="formGroup.get('state').value === 'initial'" value="initial" i18n
>Initial</mat-option
>
<mat-option value="initial" i18n>Initial</mat-option>
<mat-option value="translated" i18n>Translated</mat-option>
<mat-option value="reviewed" i18n>Reviewed</mat-option>
<mat-option value="final" i18n>Final</mat-option>
Expand Down
2 changes: 1 addition & 1 deletion src/app/target/unit/unit.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export class UnitComponent implements OnDestroy {
meaning: [{ value: unit.meaning || '-', disabled: true }],
source: [{ value: unit.source, disabled: true }],
target: unit.target,
state: [{ value: unit.state, disabled: !unit.target }],
state: unit.state,
});
this._translationTargetService.updateUnitOnChange(
unit,
Expand Down

0 comments on commit 27f76d1

Please sign in to comment.