Skip to content

Commit

Permalink
Merge pull request #84 from rvanbekkum/develop
Browse files Browse the repository at this point in the history
Release 1.1.0
  • Loading branch information
rvanbekkum authored Feb 26, 2021
2 parents 93966bf + 1708113 commit 9348b27
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 10 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## [1.1.0] 26-02-2021

* Fixed new unit nodes getting `state="translated"` with no translation. Bug due to changes for GitHub issue [#67](https://github.com/rvanbekkum/vsc-xliff-sync/issues/67). (GitHub issue [#81](https://github.com/rvanbekkum/vsc-xliff-sync/issues/81))

## [1.0.0] 21-02-2021

* Optimized syncing through a preprocessing step that builds up unit maps. The existing implementation approaches O(n^2) while this optimization implemented brings it down to O(n) (with n being the number of translation units). This optimization was already applied earlier in the PowerShell version (see [ps-xliff-sync](https://github.com/rvanbekkum/ps-xliff-sync)). The new setting `xliffSync.unitMaps` can be used to change whether and to which extent these maps should be used (**Default**: `"All"`). (GitHub issue [#31](https://github.com/rvanbekkum/vsc-xliff-sync/issues/31))
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ This extension is based on the [Angular Localization Helper](https://github.com/
It is specifically targeted at synchronizing trans-units from an `<ApplicationName>.g.xlf` file automatically generated by the [AL Language](https://marketplace.visualstudio.com/items?itemName=ms-dynamics-smb.al) extension that can be used to develop extensions for Microsoft Dynamics 365 Business Central.
Apart from synchronizing trans-units from a base-XLIFF file, this extension contributes various other features, including commands to check for missing translations, detect problems in translations and import translations from external XLIFF files.

More information: [XLIFF Sync: Time for a complete overview](https://robvanbekkum.nl/xliff-sync-overview/)

* [Features](#features)
* [Contributions](#contributions)
* [Commands](#commands)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "xliff-sync",
"displayName": "XLIFF Sync",
"description": "A tool to keep XLIFF translation files in sync.",
"version": "1.0.0",
"version": "1.1.0",
"publisher": "rvanbekkum",
"repository": {
"type": "git",
Expand Down
8 changes: 4 additions & 4 deletions src/features/tools/xlf-translator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export class XlfTranslator {
}
}

if (!translChildNodes && findBySource) {
if ((!translChildNodes || (translChildNodes.length === 1 && translChildNodes[0] === missingTranslationKeyword)) && findBySource) {
if (!(source in sourceTranslations)) {
let transUnitTrl = targetDocument.findFirstTranslationUnitBySource(source);
if (transUnitTrl) {
Expand All @@ -140,7 +140,7 @@ export class XlfTranslator {
}
}

if (!translChildNodes && (copyFromSource || parseFromDeveloperNote)) {
if ((!translChildNodes || (translChildNodes.length === 1 && translChildNodes[0] === missingTranslationKeyword)) && (copyFromSource || parseFromDeveloperNote)) {
let hasNoTranslation: boolean = false;
if (targetUnit) {
const translationText: string | undefined = targetDocument.getUnitTranslationText(targetUnit);
Expand All @@ -158,13 +158,13 @@ export class XlfTranslator {
const shouldParseFromDevNote: boolean = parseFromDeveloperNote && (hasNoTranslation || parseFromDeveloperNoteOverwrite);
const shouldCopyFromSource: boolean = copyFromSource && (hasNoTranslation || copyFromSourceOverwrite);

if (!translChildNodes && shouldParseFromDevNote) {
if ((!translChildNodes || (translChildNodes.length === 1 && translChildNodes[0] === missingTranslationKeyword)) && shouldParseFromDevNote) {
const translationFromDeveloperNote: string | undefined = mergedDocument.getUnitTranslationFromDeveloperNote(unit);
if (translationFromDeveloperNote) {
translChildNodes = [translationFromDeveloperNote];
}
}
if (!translChildNodes && shouldCopyFromSource) {
if ((!translChildNodes || (translChildNodes.length === 1 && translChildNodes[0] === missingTranslationKeyword)) && shouldCopyFromSource) {
translChildNodes = targetDocument.getUnitSourceChildren(unit);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/features/tools/xlf/xlf-document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,7 @@ export class XlfDocument {
if (needsTranslation && !targetNode) {
let attributes: { [key: string]: string; } = {};
let newTranslationState: translationState = translationState.translated;
if (!translChildNodes) {
if (!translChildNodes || (translChildNodes.length === 1 && translChildNodes[0] === this.missingTranslation)) {
translChildNodes = [this.missingTranslation];
newTranslationState = translationState.missingTranslation;
}
Expand All @@ -687,7 +687,7 @@ export class XlfDocument {
}

if (needsTranslation && targetNode) {
if (translChildNodes) {
if (translChildNodes && !(translChildNodes.length === 1 && translChildNodes[0] === this.missingTranslation)) {
targetNode.children = translChildNodes;
if (!targetNode.attributes) {
targetNode.attributes = {};
Expand Down
8 changes: 5 additions & 3 deletions src/features/trans-import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

import { ExtensionContext, window, commands, OpenDialogOptions, Uri, workspace, env, WorkspaceFolder } from "vscode";
import { ExtensionContext, window, commands, OpenDialogOptions, Uri, workspace, env, WorkspaceFolder, WorkspaceConfiguration } from "vscode";
import { XlfDocument } from './tools/xlf/xlf-document';
import { FilesHelper, WorkspaceHelper, XmlNode } from './tools';

Expand Down Expand Up @@ -88,15 +88,17 @@ async function importTranslationsFromFile(workspaceFolder: WorkspaceFolder, file
window.showErrorMessage('The provided file URI is invalid!');
return;
}
const replaceTranslationsDuringImport: boolean = workspace.getConfiguration('xliffSync', workspaceFolder.uri)['replaceTranslationsDuringImport'];
const xliffWorkspaceConfiguration: WorkspaceConfiguration = workspace.getConfiguration('xliffSync', workspaceFolder.uri);
const missingTranslationKeyword: string = xliffWorkspaceConfiguration['missingTranslation'];
const replaceTranslationsDuringImport: boolean = xliffWorkspaceConfiguration['replaceTranslationsDuringImport'];

const selFileDocument = await XlfDocument.loadFromUri(fileUri, workspaceFolder.uri);
let sourceDevNoteTranslations: { [key: string]: (XmlNode | string)[]; } = {};
selFileDocument.translationUnitNodes.forEach((unit) => {
const sourceDevNoteText = getSourceDevNoteText(selFileDocument, unit);
if (sourceDevNoteText && !(sourceDevNoteText in sourceDevNoteTranslations)) {
const translChildNodes = selFileDocument.getUnitTranslationChildren(unit);
if (translChildNodes) {
if (translChildNodes && !(translChildNodes.length === 1 && translChildNodes[0] === missingTranslationKeyword)) {
sourceDevNoteTranslations[sourceDevNoteText] = translChildNodes;
}
}
Expand Down

0 comments on commit 9348b27

Please sign in to comment.