Skip to content

Commit

Permalink
New setting xliffSync.parseFromDeveloperNoteTrimCharacters (Issue #100)
Browse files Browse the repository at this point in the history
  • Loading branch information
rvanbekkum committed Apr 29, 2022
1 parent 4e19f2a commit fc0ba6a
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 1 deletion.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Changelog

## [1.3.0]

* New setting `xliffSync.parseFromDeveloperNoteTrimCharacters` that can be used to specify the characters to trim from the translations parsed from the developer notes. (GitHub issue [#100](https://github.com/rvanbekkum/vsc-xliff-sync/issues/100))
* Included `needs-l10n` to be considered as a needs-work state. (GitHub issue [#102](https://github.com/rvanbekkum/vsc-xliff-sync/issues/102))

### Thank You

* **[fvet](https://github.com/fvet)** for your feature request for setting `xliffSync.parseFromDeveloperNoteTrimCharacters` (GitHub issue [#100](https://github.com/rvanbekkum/vsc-xliff-sync/issues/100))

## [1.2.0] 21-06-2021

* Fixed "Open Externally" no longer working after Visual Studio Code update 1.57.0. This may be a work-around that will be reverted later on. (GitHub issue [#89](https://github.com/rvanbekkum/vsc-xliff-sync/issues/89))
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ More information: [XLIFF Sync: Time for a complete overview](https://robvanbekku
| xliffSync.parseFromDeveloperNote | `false` | Specifies whether translations should be parsed from the developer note. Translations can be retrieved from a Developer note in the following format: <code>en-US=My translation&#124;nl-NL=Mijn vertaling</code>. |
| xliffSync.parseFromDeveloperNoteOverwrite | `false` | Specifies whether translations parsed from the developer note should always overwrite existing translations. |
| xliffSync.parseFromDeveloperNoteSeparator | <code>&#124;</code> | Specifies the separator that is used when translations are parsed from the developer note. |
| xliffSync.parseFromDeveloperNoteTrimCharacters | `` | Specifies the characters that will be trimmed from the translation. |
| xliffSync.equivalentLanguages | `{ "de-DE": "de-.*", "en-US": "en-.*", "es-ES": "es-.*", "fr-FR": "fr-.*", "nl-NL": "nl-.*" }` | Specifies master and slave languages that should be treated as equivalent, i.e., translations are copied from the master language. |
| xliffSync.equivalentLanguagesEnabled | `false` | Specifies whether languages should be treated as equivalent as specified in the xliffSync.equivalentLanguages setting. |
| xliffSync.copyFromSourceForLanguages | `[]` | Specifies the languages for which translations should be copied from the source text of trans-units. |
Expand Down
8 changes: 7 additions & 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.2.0",
"version": "1.3.0",
"publisher": "rvanbekkum",
"repository": {
"type": "git",
Expand Down Expand Up @@ -139,6 +139,12 @@
"description": "Specifies the separator that is used when translations are parsed from the developer note.",
"scope": "resource"
},
"xliffSync.parseFromDeveloperNoteTrimCharacters": {
"type": "string",
"default": "",
"description": "Specifies the characters that will be trimmed from the translation.",
"scope": "resource"
},
"xliffSync.equivalentLanguages": {
"type": "object",
"additionalProperties": {
Expand Down
23 changes: 23 additions & 0 deletions src/features/tools/xlf/xlf-document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ export class XlfDocument {
private preserveTargetOrder: boolean;
private preserveTargetChildNodes: boolean;
private parseFromDeveloperNoteSeparator: string;
private parseFromDeveloperNoteTrimCharacters: string;
private missingTranslation: string;
private needsWorkTranslationSubstate: string;
private addNeedsWorkTranslationNote: boolean;
Expand All @@ -187,6 +188,7 @@ export class XlfDocument {
this.preserveTargetOrder = xliffWorkspaceConfiguration['preserveTargetAttributesOrder'];
this.preserveTargetChildNodes = xliffWorkspaceConfiguration['preserveTargetChildNodes'];
this.parseFromDeveloperNoteSeparator = xliffWorkspaceConfiguration['parseFromDeveloperNoteSeparator'];
this.parseFromDeveloperNoteTrimCharacters = xliffWorkspaceConfiguration['parseFromDeveloperNoteTrimCharacters'];

this.missingTranslation = xliffWorkspaceConfiguration['missingTranslation'];
if (this.missingTranslation === '%EMPTY%') {
Expand Down Expand Up @@ -597,9 +599,30 @@ export class XlfDocument {
}
}

if (this.parseFromDeveloperNoteTrimCharacters != "") {
translation = this.trimAny(translation, this.parseFromDeveloperNoteTrimCharacters)
}

return translation;
}

private trimAny(str: string | undefined, chars: string): string | undefined {
if (!str) {
return str;
}

var start = 0;
var end = str.length;

while(start < end && chars.indexOf(str[start]) >= 0)
++start;

while(end > start && chars.indexOf(str[end - 1]) >= 0)
--end;

return (start > 0 || end < str.length) ? str.substring(start, end) : str;
}

public mergeUnit(sourceUnit: XmlNode, targetUnit: XmlNode | undefined, translChildNodes: (XmlNode | string)[] | undefined): void {
let targetNode: XmlNode | undefined;

Expand Down

0 comments on commit fc0ba6a

Please sign in to comment.