From e3d42e81259ce132cd77cb59076ff4b2b691bc87 Mon Sep 17 00:00:00 2001 From: rvanbekkum Date: Mon, 3 Aug 2020 22:06:15 +0200 Subject: [PATCH 1/6] Various updates for XLIFF 2.0 support --- CHANGELOG.md | 10 +++ README.md | 1 + package.json | 8 +- src/features/tools/files-helper.ts | 20 ++++- src/features/tools/xlf-translator.ts | 3 +- src/features/tools/xlf/xlf-document.ts | 77 +++++++++++++++++-- .../tools/xlf/xlf-translationState.ts | 5 ++ src/features/trans-check.ts | 5 +- 8 files changed, 115 insertions(+), 14 deletions(-) create mode 100644 src/features/tools/xlf/xlf-translationState.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index b3deb79..95f8937 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,15 @@ # Changelog +## [0.5.0] + +* Better XLIFF 2.0 support: + * `state` attribute on `segment` nodes instead of target nodes. + * `state` and `subState` used: + * `needs-translation` -> `initial` with no sub-state + * `needs-adapatation` -> `translated` with sub-state configurable with setting `xliffSync.needsWorkTranslationSubstate`. + * `translated` -> `translated` with no sub-state. + * Let `xliffSync.fileType` = `xlf2` work with file-extension `xlf`. + ## [0.4.0] 02-08-2020 * New setting `xliffSync.syncCrossWorkspaceFolders` which can be used to set that the extension should synchronize from one single base file (`xliffSync.baseFile`) to the translation files in all workspace folders (**Default**: `false`) (GitHub issue [#48](https://github.com/rvanbekkum/vsc-xliff-sync/issues/48)). diff --git a/README.md b/README.md index 95153ba..588b048 100644 --- a/README.md +++ b/README.md @@ -60,6 +60,7 @@ Apart from synchronizing trans-units from a base-XLIFF file, this extension cont | xliffSync.fileType | `xlf` | The file type (`xlf` or `xlf2`). | | xliffSync.syncCrossWorkspaceFolders | `false` | Specifies whether the extension will sync from a base file to the translation files in all workspace folders. By default, the extension will always sync. per workspace folder. If you enable this setting, then you can have the base file in one workspace folder and target translation files in other workspace folders. | | xliffSync.missingTranslation | `%EMPTY%` | The placeholder for missing translations for trans-units that were synced/merged into target XLIFF files. You can use `%EMPTY%` if you want to use an empty string for missing translations. | +| xliffSync.needsWorkTranslationSubstate | `poedit:fuzzy`| Specifies the substate to use for translations that need work in xlf2 files. | | xliffSync.findByXliffGeneratorNoteAndSource | `true` | Specifies whether or not the extension will try to find trans-units by XLIFF generator note and source. | | xliffSync.findByXliffGeneratorAndDeveloperNote | `true` | Specifies whether or not the extension will try to find trans-units by XLIFF generator note and developer note. | | xliffSync.findByXliffGeneratorNote | `true` | Specifies whether or not the extension will try to find trans-units by XLIFF generator note. | diff --git a/package.json b/package.json index 61c718f..b7ec017 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "xliff-sync", "displayName": "XLIFF Sync", "description": "A tool to keep XLIFF translation files in sync.", - "version": "0.4.0", + "version": "0.5.0", "publisher": "rvanbekkum", "repository": { "type": "git", @@ -151,6 +151,12 @@ "description": "Target tag content for missing translation (use %EMPTY% to leave new targets empty).", "scope": "resource" }, + "xliffSync.needsWorkTranslationSubstate": { + "type": "string", + "default": "poedit:fuzzy", + "description": "Specifies the substate to use for translations that need work in xlf2 files.", + "scope": "resource" + }, "xliffSync.developerNoteDesignation": { "type": "string", "default": "Developer", diff --git a/src/features/tools/files-helper.ts b/src/features/tools/files-helper.ts index 18d76e5..5501e5a 100644 --- a/src/features/tools/files-helper.ts +++ b/src/features/tools/files-helper.ts @@ -130,16 +130,16 @@ export class FilesHelper { return sourceUri; } - public static async findTranslationFiles(fileExt: string, workspaceFolder?: WorkspaceFolder): Promise { + public static async findTranslationFiles(fileType: string, workspaceFolder?: WorkspaceFolder): Promise { if (workspaceFolder) { - return await FilesHelper.findTranslationFilesInWorkspaceFolder(fileExt, workspaceFolder); + return await FilesHelper.findTranslationFilesInWorkspaceFolder(fileType, workspaceFolder); } else { let allFileUris: Uri[] = []; const workspaceFolders: WorkspaceFolder[] | undefined = await WorkspaceHelper.getWorkspaceFolders(true); if (workspaceFolders) { for (let wsFolder of workspaceFolders) { - let folderFileUris: Uri[] = await FilesHelper.findTranslationFilesInWorkspaceFolder(fileExt, wsFolder); + let folderFileUris: Uri[] = await FilesHelper.findTranslationFilesInWorkspaceFolder(fileType, wsFolder); allFileUris = allFileUris.concat(folderFileUris); } } @@ -147,7 +147,9 @@ export class FilesHelper { } } - public static async findTranslationFilesInWorkspaceFolder(fileExt: string, workspaceFolder: WorkspaceFolder): Promise { + public static async findTranslationFilesInWorkspaceFolder(fileType: string, workspaceFolder: WorkspaceFolder): Promise { + const fileExt: string = FilesHelper.getTranslationFileExtensions(fileType); + let relativePattern: RelativePattern = new RelativePattern(workspaceFolder, `**/*.${fileExt}`); return workspace.findFiles(relativePattern).then((files) => files.sort((a, b) => { @@ -159,6 +161,16 @@ export class FilesHelper { ); } + public static getTranslationFileExtensions(fileType: string): string { + switch(fileType) { + case 'xlf': + return 'xlf'; + case 'xlf2': + return 'xlf*'; + } + return 'xlf'; + } + public static async createTranslationFile( language: string, baseUri: Uri, diff --git a/src/features/tools/xlf-translator.ts b/src/features/tools/xlf-translator.ts index 59fd563..29aeb50 100644 --- a/src/features/tools/xlf-translator.ts +++ b/src/features/tools/xlf-translator.ts @@ -24,6 +24,7 @@ import { workspace, WorkspaceConfiguration, WorkspaceFolder } from 'vscode'; import { XlfDocument } from './xlf/xlf-document'; +import { translationState } from './xlf/xlf-translationState'; export class XlfTranslator { public static async synchronize( @@ -160,7 +161,7 @@ export class XlfTranslator { if (mergedSourceText !== origSourceText) { mergedDocument.setXliffSyncNote(unit, 'Source text has changed. Please review the translation.'); - mergedDocument.setTargetAttribute(unit, 'state', 'needs-adaptation'); + mergedDocument.setState(unit, translationState.needsWorkTranslation); } } } diff --git a/src/features/tools/xlf/xlf-document.ts b/src/features/tools/xlf/xlf-document.ts index 4816b0e..b56655e 100644 --- a/src/features/tools/xlf/xlf-document.ts +++ b/src/features/tools/xlf/xlf-document.ts @@ -24,6 +24,7 @@ import { XmlNode, XmlParser, XmlBuilder } from '..'; import { workspace, Uri, WorkspaceConfiguration } from 'vscode'; +import { translationState } from './xlf-translationState'; export class XlfDocument { public get valid(): boolean { @@ -157,6 +158,7 @@ export class XlfDocument { private preserveTargetOrder: boolean; private parseFromDeveloperNoteSeparator: string; private missingTranslation: string; + private needsWorkTranslationSubstate: string; private constructor(resourceUri: Uri | undefined) { const xliffWorkspaceConfiguration: WorkspaceConfiguration = workspace.getConfiguration('xliffSync', resourceUri); @@ -170,6 +172,7 @@ export class XlfDocument { if (this.missingTranslation === '%EMPTY%') { this.missingTranslation = ''; } + this.needsWorkTranslationSubstate = xliffWorkspaceConfiguration['needsWorkTranslationSubstate']; } public static async load(source: string, resourceUri: Uri | undefined): Promise { @@ -449,10 +452,10 @@ export class XlfDocument { let attributes: { [key: string]: string; } = {}; if (!translation) { translation = this.missingTranslation; - attributes['state'] = 'needs-translation'; + this.updateStateAttributes(attributes, translationState.missingTranslation); } else { - attributes['state'] = 'translated'; + this.updateStateAttributes(attributes, translationState.translated); } targetNode = this.createTargetNode(sourceUnit, attributes, translation); @@ -467,12 +470,46 @@ export class XlfDocument { if (!targetNode.attributes) { targetNode.attributes = {}; } - targetNode.attributes['state'] = 'translated'; + this.updateStateAttributes(targetNode.attributes, translationState.translated); } this.appendTargetNode(sourceUnit, targetNode); } } + public updateStateAttributes(attributes: { [key: string]: string; }, newState: translationState) { + switch (this.version) { + case '1.2': + switch (newState) { + case translationState.missingTranslation: + attributes['state'] = 'needs-translation'; + break; + case translationState.needsWorkTranslation: + attributes['state'] = 'needs-adaptation'; + break; + case translationState.translated: + attributes['state'] = 'translated'; + break; + } + break; + case '2.0': + switch (newState) { + case translationState.missingTranslation: + attributes['state'] = 'initial'; + delete attributes["subState"]; + break; + case translationState.needsWorkTranslation: + attributes['state'] = 'translated'; + attributes['subState'] = this.needsWorkTranslationSubstate; + break; + case translationState.translated: + attributes['state'] = 'translated'; + delete attributes["subState"]; + break; + } + break; + } + } + public createTargetNode(parentUnit: XmlNode, attributes: { [key: string]: string; }, translation: string): XmlNode { return { name: 'target', @@ -548,8 +585,23 @@ export class XlfDocument { return undefined; } + private tryGetStateNode(unit: XmlNode): XmlNode | undefined { + let stateNodeTag: string = 'target'; + switch (this.version) { + case '1.2': + stateNodeTag = 'target'; + break; + case '2.0': + stateNodeTag = 'segment'; + break; + } + + return this.getNode(stateNodeTag, unit); + } + + public setTargetAttribute(unit: XmlNode, attribute: string, attributeValue: string) { - let targetNode = this.getNode('target', unit); + let targetNode: XmlNode | undefined = this.getNode('target', unit); if (!targetNode) { let attributes: { [key: string]: string; } = {}; attributes[attribute] = attributeValue; @@ -561,6 +613,19 @@ export class XlfDocument { } } + public setState(unit: XmlNode, newState: translationState) { + let stateNode = this.tryGetStateNode(unit); + if (!stateNode && this.version === '1.2') { + let attributes: { [key: string]: string; } = {}; + this.updateStateAttributes(attributes, newState); + let targetNode: XmlNode = this.createTargetNode(unit, attributes, ""); + this.appendTargetNode(unit, targetNode); + } + else if (stateNode) { + this.updateStateAttributes(stateNode.attributes, newState); + } + } + private deleteTargetNode(unit: XmlNode) { if (unit) { const index = unit.children.indexOf('target', 0); @@ -583,8 +648,8 @@ export class XlfDocument { notesParent = this.getNode('notes', unit); if (!notesParent) { notesParent = { - name: 'note', - local: 'note', + name: 'notes', + local: 'notes', parent: unit, attributes: {}, children: [], diff --git a/src/features/tools/xlf/xlf-translationState.ts b/src/features/tools/xlf/xlf-translationState.ts new file mode 100644 index 0000000..45b1dd5 --- /dev/null +++ b/src/features/tools/xlf/xlf-translationState.ts @@ -0,0 +1,5 @@ +export enum translationState { + missingTranslation = 0, + needsWorkTranslation = 1, + translated = 10 +} diff --git a/src/features/trans-check.ts b/src/features/trans-check.ts index 9648522..bf77611 100644 --- a/src/features/trans-check.ts +++ b/src/features/trans-check.ts @@ -39,6 +39,7 @@ import { } from 'vscode'; import { XlfDocument } from './tools/xlf/xlf-document'; import { FilesHelper, WorkspaceHelper, XmlNode } from './tools'; +import { translationState } from './tools/xlf/xlf-translationState'; // Variables that should be accessible from events var currentEditor: TextEditor | undefined; @@ -330,11 +331,11 @@ export async function runTranslationChecksForWorkspaceFolder(shouldCheckForMissi targetDocument.translationUnitNodes.forEach((unit) => { if (shouldCheckForMissingTranslations && checkForMissingTranslation(targetDocument, unit, missingTranslationText)) { - targetDocument.setTargetAttribute(unit, 'state', 'needs-translation'); + targetDocument.setState(unit, translationState.missingTranslation); missingCount += 1; } if (shouldCheckForNeedWorkTranslations && checkForNeedWorkTranslation(targetDocument, unit, isRuleEnabledChecker, sourceEqualsTargetExpected)) { - targetDocument.setTargetAttribute(unit, 'state', 'needs-adaptation'); + targetDocument.setState(unit, translationState.needsWorkTranslation); needWorkCount += 1; } if (shouldCheckForNeedWorkTranslations && checkForResolvedProblem(targetDocument, unit)) { From 6975b49f3fc2610498cdc1d2f92c08491ec37903 Mon Sep 17 00:00:00 2001 From: rvanbekkum Date: Mon, 3 Aug 2020 22:18:39 +0200 Subject: [PATCH 2/6] Update CHANGELOG --- CHANGELOG.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 95f8937..7cec858 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,10 @@ * `translated` -> `translated` with no sub-state. * Let `xliffSync.fileType` = `xlf2` work with file-extension `xlf`. +### Thank You + +* **[antpyykk](https://github.com/antpyykk)** for filing the issue with states for XLIFF 2.0 files (GitHub issue [#50](https://github.com/rvanbekkum/vsc-xliff-sync/issues/50)) + ## [0.4.0] 02-08-2020 * New setting `xliffSync.syncCrossWorkspaceFolders` which can be used to set that the extension should synchronize from one single base file (`xliffSync.baseFile`) to the translation files in all workspace folders (**Default**: `false`) (GitHub issue [#48](https://github.com/rvanbekkum/vsc-xliff-sync/issues/48)). @@ -28,6 +32,10 @@ * You can configure for which programming languages the snippets should be available with setting `xliffSync.enableSnippetsForLanguages`. Currently only the "AL Language" is supported with snippets: `tcaptionwithtranslation`, `tcommentwithtranslation`, `toptioncaptionwithtranslation`, `tpromotedactioncategorieswithtranslation`, `tlabelwithtranslation` and `ttooltipwithtranslation` snippets. * You can configure a default target language that should be used by the snippets with setting `xliffSync.snippetTargetLanguage`. +### Thank You + +* **[GregoryAA](https://github.com/GregoryAA)** for requesting the _Parse from Developer Note_ feature enhancements. (GitHub issue [#43](https://github.com/rvanbekkum/vsc-xliff-sync/issues/43)) + ## [0.3.7] 18-05-2020 * New setting `xliffSync.detectSourceTextChanges` (see README) From 37f69c928b551223b3cbd4343b5d590de922d748 Mon Sep 17 00:00:00 2001 From: rvanbekkum Date: Mon, 3 Aug 2020 22:20:28 +0200 Subject: [PATCH 3/6] Fix typo in CHANGELOG --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7cec858..5c1bc14 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ * `state` attribute on `segment` nodes instead of target nodes. * `state` and `subState` used: * `needs-translation` -> `initial` with no sub-state - * `needs-adapatation` -> `translated` with sub-state configurable with setting `xliffSync.needsWorkTranslationSubstate`. + * `needs-adaptation` -> `translated` with sub-state configurable with setting `xliffSync.needsWorkTranslationSubstate`. * `translated` -> `translated` with no sub-state. * Let `xliffSync.fileType` = `xlf2` work with file-extension `xlf`. From 66a9dece118d7f8b7656370d7260f064281062c0 Mon Sep 17 00:00:00 2001 From: rvanbekkum Date: Wed, 5 Aug 2020 23:06:46 +0200 Subject: [PATCH 4/6] Various XLIFF 2.0 'needs-work' fixes --- CHANGELOG.md | 5 +++ package.json | 2 +- src/features/tools/xlf/xlf-document.ts | 62 +++++++++++++++++++++++--- src/features/trans-check.ts | 4 +- 4 files changed, 63 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5c1bc14..ac3364a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,11 @@ * `needs-adaptation` -> `translated` with sub-state configurable with setting `xliffSync.needsWorkTranslationSubstate`. * `translated` -> `translated` with no sub-state. * Let `xliffSync.fileType` = `xlf2` work with file-extension `xlf`. + * Fix: function `findXliffSyncNoteIndex` should check for the "category" attribute instead of the "from" attribute. + * Fix: function `tryDeleteXliffSyncNote` should call `findXliffSyncNoteIndex` with `notesParent` as argument instead of `unit`. + * Fix: function `setXliffSyncNote` should only add a new `notes` node in XLIFF 2.0 files if it does not exist for a unit. + * Fix: function `setXliffSyncNote` should call `findXliffSyncNoteIndex` to check if an XLIFF Sync note already exists. + * "Check for Need Work Translations" now considers the `xliffSync.needsWorkTranslationSubstate` substate. ### Thank You diff --git a/package.json b/package.json index b7ec017..8243c71 100644 --- a/package.json +++ b/package.json @@ -153,7 +153,7 @@ }, "xliffSync.needsWorkTranslationSubstate": { "type": "string", - "default": "poedit:fuzzy", + "default": "xliffSync:needsWork", "description": "Specifies the substate to use for translations that need work in xlf2 files.", "scope": "resource" }, diff --git a/src/features/tools/xlf/xlf-document.ts b/src/features/tools/xlf/xlf-document.ts index b56655e..9f81a6d 100644 --- a/src/features/tools/xlf/xlf-document.ts +++ b/src/features/tools/xlf/xlf-document.ts @@ -585,6 +585,43 @@ export class XlfDocument { return undefined; } + public getState(unit: XmlNode): translationState | undefined { + let stateNode: XmlNode | undefined = this.tryGetStateNode(unit); + if (stateNode && stateNode.attributes) { + switch (this.version) { + case '1.2': + { + const state: string | undefined = stateNode.attributes['state']; + switch (state) { + case 'needs-translation': + return translationState.missingTranslation; + case 'needs-adaptation': + return translationState.needsWorkTranslation; + case 'translated': + return translationState.translated; + } + break; + } + case '2.0': + { + const state: string | undefined = stateNode.attributes['state']; + switch (state) { + case 'initial': + return translationState.missingTranslation; + case 'translated': + if (stateNode.attributes['subState'] === this.needsWorkTranslationSubstate) { + return translationState.needsWorkTranslation; + } + else { + return translationState.translated; + } + } + } + } + } + return undefined; + } + private tryGetStateNode(unit: XmlNode): XmlNode | undefined { let stateNodeTag: string = 'target'; switch (this.version) { @@ -657,8 +694,8 @@ export class XlfDocument { prefix: '', uri: '', }; + unit.children.push(notesParent); } - unit.children.push(notesParent); break; default: return; @@ -677,9 +714,7 @@ export class XlfDocument { uri: '', }; - let noteIdx = notesParent.children.findIndex( - (child) => typeof child !== 'string' && child.name === 'note' && child.attributes && child.attributes['from'] === fromAttribute, - ); + const noteIdx: number = this.findXliffSyncNoteIndex(notesParent); let targetIdx = unit.children.findIndex( (child) => typeof child !== 'string' && child && child.name === 'target', ); @@ -697,7 +732,7 @@ export class XlfDocument { public tryDeleteXliffSyncNote(unit: XmlNode): boolean { let notesParent: XmlNode | undefined = this.getNotesParent(unit); if (notesParent) { - const noteIdx: number = this.findXliffSyncNoteIndex(unit); + const noteIdx: number = this.findXliffSyncNoteIndex(notesParent); if (noteIdx >= 0) { let deleteCount: number = 1; @@ -719,9 +754,22 @@ export class XlfDocument { return -1; } - const fromAttribute = 'XLIFF Sync'; + let categoryAttributeName: string; + switch (this.version) { + case '1.2': + categoryAttributeName = 'from'; + break; + case '2.0': + categoryAttributeName = 'category'; + break; + default: + categoryAttributeName = 'from'; + break; + } + const categoryAttributeValue: string = 'XLIFF Sync'; + return notesParent.children.findIndex( - (child) => typeof child !== 'string' && child.name === 'note' && child.attributes && child.attributes['from'] === fromAttribute, + (child) => typeof child !== 'string' && child.name === 'note' && child.attributes && (child.attributes[categoryAttributeName] === categoryAttributeValue), ); } diff --git a/src/features/trans-check.ts b/src/features/trans-check.ts index bf77611..c333501 100644 --- a/src/features/trans-check.ts +++ b/src/features/trans-check.ts @@ -456,7 +456,7 @@ function checkForNeedWorkTranslation(targetDocument: XlfDocument, unit: XmlNode, return true; } - if (targetDocument.getTargetAttribute(unit, 'state') === 'needs-adaptation') { + if (targetDocument.getState(unit) === translationState.needsWorkTranslation) { return true; } @@ -464,7 +464,7 @@ function checkForNeedWorkTranslation(targetDocument: XlfDocument, unit: XmlNode, } function checkForResolvedProblem(targetDocument: XlfDocument, unit: XmlNode) : boolean { - return targetDocument.getTargetAttribute(unit, 'state') !== 'needs-adaptation' && targetDocument.tryDeleteXliffSyncNote(unit); + return targetDocument.getState(unit) !== translationState.needsWorkTranslation && targetDocument.tryDeleteXliffSyncNote(unit); } function checkForPlaceHolderMismatch(sourceText: string, translationText: string) { From 1fcbdd4841062ac7d2de3f2d75c62c382772ddf4 Mon Sep 17 00:00:00 2001 From: rvanbekkum Date: Wed, 5 Aug 2020 23:11:52 +0200 Subject: [PATCH 5/6] Update README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 588b048..ccf4a7e 100644 --- a/README.md +++ b/README.md @@ -60,7 +60,7 @@ Apart from synchronizing trans-units from a base-XLIFF file, this extension cont | xliffSync.fileType | `xlf` | The file type (`xlf` or `xlf2`). | | xliffSync.syncCrossWorkspaceFolders | `false` | Specifies whether the extension will sync from a base file to the translation files in all workspace folders. By default, the extension will always sync. per workspace folder. If you enable this setting, then you can have the base file in one workspace folder and target translation files in other workspace folders. | | xliffSync.missingTranslation | `%EMPTY%` | The placeholder for missing translations for trans-units that were synced/merged into target XLIFF files. You can use `%EMPTY%` if you want to use an empty string for missing translations. | -| xliffSync.needsWorkTranslationSubstate | `poedit:fuzzy`| Specifies the substate to use for translations that need work in xlf2 files. | +| xliffSync.needsWorkTranslationSubstate | `xliffSync:needsWork` | Specifies the substate to use for translations that need work in xlf2 files. **Tip**: If you use [Poedit](https://poedit.net/), then you could also set this to `poedit:fuzzy`. | | xliffSync.findByXliffGeneratorNoteAndSource | `true` | Specifies whether or not the extension will try to find trans-units by XLIFF generator note and source. | | xliffSync.findByXliffGeneratorAndDeveloperNote | `true` | Specifies whether or not the extension will try to find trans-units by XLIFF generator note and developer note. | | xliffSync.findByXliffGeneratorNote | `true` | Specifies whether or not the extension will try to find trans-units by XLIFF generator note. | From a44947c642026a3a128fc49ca647723f33003417 Mon Sep 17 00:00:00 2001 From: rvanbekkum Date: Sat, 8 Aug 2020 14:03:38 +0200 Subject: [PATCH 6/6] Update getNeedsWorkTranslationKeywords for xlf2 --- CHANGELOG.md | 5 +++-- src/features/trans-check.ts | 16 ++++++++++++++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ac3364a..7c2c35a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # Changelog -## [0.5.0] +## [0.5.0] 08-08-2020 * Better XLIFF 2.0 support: * `state` attribute on `segment` nodes instead of target nodes. @@ -13,7 +13,8 @@ * Fix: function `tryDeleteXliffSyncNote` should call `findXliffSyncNoteIndex` with `notesParent` as argument instead of `unit`. * Fix: function `setXliffSyncNote` should only add a new `notes` node in XLIFF 2.0 files if it does not exist for a unit. * Fix: function `setXliffSyncNote` should call `findXliffSyncNoteIndex` to check if an XLIFF Sync note already exists. - * "Check for Need Work Translations" now considers the `xliffSync.needsWorkTranslationSubstate` substate. + * "Check for Need Work Translations" now considers the `xliffSync.needsWorkTranslationSubstate` sub-state. + * Decoration is now also applied on `segment` nodes with the `xliffSync.needsWorkTranslationSubstate` sub-state. ### Thank You diff --git a/src/features/trans-check.ts b/src/features/trans-check.ts index c333501..ba4935d 100644 --- a/src/features/trans-check.ts +++ b/src/features/trans-check.ts @@ -254,11 +254,23 @@ export class XliffTranslationChecker { } private getNeedsWorkTranslationKeywords() : string { + const currentWorkspaceFolder: WorkspaceFolder | undefined = window.activeTextEditor ? + workspace.getWorkspaceFolder(window.activeTextEditor.document.uri) : + undefined; + let currentWorkspaceFolderUri: Uri | undefined = undefined; + if (currentWorkspaceFolder) { + currentWorkspaceFolderUri = currentWorkspaceFolder.uri; + } + let needsWorkTranslationSubstate = workspace.getConfiguration('xliffSync', currentWorkspaceFolderUri)[ + 'needsWorkTranslationSubstate' + ]; + + const segmentNeedsWorkRegExp: string = `()`; if (decorationTargetTextOnly) { - return '(?<=).*(?=)'; + return `((?<=).*(?=))|${segmentNeedsWorkRegExp}`; } else { - return '.*|'; + return `(.*)|()|${segmentNeedsWorkRegExp}`; } } }