Skip to content

Commit

Permalink
Merge pull request #30 from rvanbekkum/feature/29-placeholder-dev-note
Browse files Browse the repository at this point in the history
Placeholder Dev. Note Explanation check + New setting to enable all rules
  • Loading branch information
rvanbekkum authored Nov 3, 2019
2 parents 72eef24 + 2b0a24b commit 0d45561
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 13 deletions.
17 changes: 16 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
# Changelog

## [0.3.1]
## [0.3.2] 03-11-2019

* Added the following new technical check (disabled by default):

* `PlaceholdersDevNote` - Checks that the meaning of placeholders are explained in the Developer note.

* Added new setting `xliffSync.needWorkTranslationRulesEnableAll` to enable all available technical validation rules. If you want to use all rules including those that will be added in the future, you can use this setting. (**Default**: `false`)

* Fix: The XLIFF Sync note would only be removed for the first trans-unit where a problem is resolved. From now on, the XLIFF Sync note will be removed directly from all trans-units where the problems are detected to be resolved.

## [0.3.1] 20-10-2019

* Fix remove duplicate language tag entry `ja-JP` which shows up calling `XLIFF: Create New Target File(s)`.
* Changed `XLIFF: Create New Target File(s)` command adding two options **Select multiple..** (to select multiple target languages to create a file) and **Enter custom...** (to enter a custom target language tag).
Expand All @@ -9,6 +19,11 @@
* `ConsecutiveSpacesConsistent` - Checks that the 'consecutive space'-occurrences match in source and translation.
* `ConsecutiveSpacesExist` - Checks whether consecutive spaces exist in the source or translation text.

### Thank You

* **[fvet](https://github.com/fvet)** for requesting these new rules to be added. (GitHub issue [#25](https://github.com/rvanbekkum/vsc-xliff-sync/issues/25))
* **[pmoison](https://github.com/pmoison)** for reporting and explaining your issue which led to the changes to command `XLIFF: Create New Target File(s)`. (GitHub issue [#26](https://github.com/rvanbekkum/vsc-xliff-sync/issues/26))

## [0.3.0] 15-09-2019

* Added support for multi-root workspaces. You can configure settings per workspace folder. The commands of the extension will run for all workspace folders by default, but if you have a file opened in the editor from a workspace folder, then the commands will only run for the XLIFF files in that workspace folder.
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ Apart from synchronizing trans-units from a base-XLIFF file, this extension cont
| xliffSync.autoCheckMissingTranslations | `false` | Specifies whether or not the extension should automatically check for missing translations after syncing. |
| xliffSync.autoCheckNeedWorkTranslations | `false` | Specifies whether or not the extension should automatically run a technical validation on translations after syncing |
| xliffSync.needWorkTranslationRules | `["OptionMemberCount", "OptionLeadingSpaces", "Placeholders"]` | Specifies which technical validation rules should be used. |
| xliffSync.needWorkTranslationRulesEnableAll | `false` | Specifies whether or not all available technical validation rules should be used. Enabling this setting makes `xliffSync.needWorkTranslationRules` redundant. |
| xliffSync.preserveTargetAttributes | `false` | Specifies whether or not syncing should use the attributes from the target files for the trans-unit nodes while syncing. |
| xliffSync.preserveTargetAttributesOrder | `false` | Specifies whether the attributes of trans-unit nodes should use the order found in the target files while syncing. |
| xliffSync.replaceTranslationsDuringImport | `false` | Specifies whether existing translations will be replaced when the XLIFF: Import Translations from File(s) command is run. |
Expand Down Expand Up @@ -185,6 +186,7 @@ The currently implemented checks are the following:
| `OptionMemberCount` | Number of options in caption are not matching. | Xliff Generator note with `Property OptionCaption` or `Property PromotedActionCategories`. | The source text includes 3 options, `A,B,C` , but the translation text includes 4 options, `A,B,C,D`. |
| `OptionLeadingSpaces` | Number of leading spaces in options are not matching. | Xliff Generator note with `Property OptionCaption` or `Property PromotedActionCategories`. | The source text includes a space, `A, B` , but the translation text does not, `A,B`. |
| `Placeholders` | Placeholders of source and translation are not matching. | Source/Translation text includes placeholders of the form `{0}` or `%1`. | The source text includes placeholders `%1 %2` , but the translation text only includes `%1`. |
| `PlaceholdersDevNote` | Placeholders are not explained in the Developer note. | Source text includes placeholders of the form `{0}` or `%1`. | The source text includes placeholders `%1 %2` , but the Developer note is empty and so does not contain the placeholders. |
| `SourceEqualsTarget` | Source and translation are not the same, even though source-language = target-language for the .xlf file. | The source-language is the same as the target-language for the .xlf file. | The source text is 'A', but the translation text is 'B'. The source-language and target-language are both 'en-US'. |

**Note**: You may want to use rule `SourceEqualsTarget` in combination with setting `xliffSync.copyFromSourceForSameLanguage` set to `true`.
Expand Down
12 changes: 10 additions & 2 deletions 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": "0.3.1",
"version": "0.3.2",
"publisher": "rvanbekkum",
"repository": {
"type": "git",
Expand Down Expand Up @@ -132,6 +132,7 @@
"OptionMemberCount",
"OptionLeadingSpaces",
"Placeholders",
"PlaceholdersDevNote",
"SourceEqualsTarget"
],
"enumDescriptions": [
Expand All @@ -140,6 +141,7 @@
"Checks that the number of members of the OptionCaption or PromotedActionCategories property match.",
"Checks that the leading spaces of members of the OptionCaption or PromotedActionCategories property match.",
"Checks that the number of placeholders match.",
"Checks that the meaning of placeholders are explained in the Developer note.",
"Checks that the source and target are the same for files where source and target language are the same."
]
},
Expand All @@ -151,7 +153,13 @@
"uniqueItems": true,
"description": "Specifies which technical validation rules should be used.",
"scope": "resource"
},
},
"xliffSync.needWorkTranslationRulesEnableAll": {
"type" : "boolean",
"default" : false,
"description": "Specifies whether or not all available technical validation rules should be used. Enabling this setting makes xliffSync.needWorkTranslationRules redundant.",
"scope": "resource"
},
"xliffSync.preserveTargetAttributes": {
"type" : "boolean",
"default" : false,
Expand Down
31 changes: 21 additions & 10 deletions src/features/trans-check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,12 @@ export async function runTranslationChecksForWorkspaceFolder(checkWorkspaceFolde
let needWorkRules: string[] = workspace.getConfiguration('xliffSync', checkWorkspaceFolder.uri)[
'needWorkTranslationRules'
];
let needWorkRulesEnableAll: boolean = workspace.getConfiguration('xliffSync', checkWorkspaceFolder.uri)[
'needWorkTranslationRulesEnableAll'
];
function isRuleEnabledChecker(ruleName: string): boolean {
return needWorkRulesEnableAll || needWorkRules.indexOf(ruleName) >= 0;
}

let noMissingTranslations: boolean = true;
let noNeedWorkTranslations: boolean = true;
Expand All @@ -273,11 +279,11 @@ export async function runTranslationChecksForWorkspaceFolder(checkWorkspaceFolde
targetDocument.setTargetAttribute(unit, 'state', 'needs-translation');
missingCount += 1;
}
if (shouldCheckForNeedWorkTranslations && checkForNeedWorkTranslation(targetDocument, unit, needWorkRules)) {
if (shouldCheckForNeedWorkTranslations && checkForNeedWorkTranslation(targetDocument, unit, isRuleEnabledChecker)) {
targetDocument.setTargetAttribute(unit, 'state', 'needs-adaptation');
needWorkCount += 1;
}
if (shouldCheckForNeedWorkTranslations && !problemResolvedInFile && checkForResolvedProblem(targetDocument, unit)) {
if (shouldCheckForNeedWorkTranslations && checkForResolvedProblem(targetDocument, unit)) {
problemResolvedInFile = true;
}
});
Expand Down Expand Up @@ -342,37 +348,42 @@ function checkForMissingTranslation(targetDocument: XlfDocument, unit: XmlNode,
return false;
}

function checkForNeedWorkTranslation(targetDocument: XlfDocument, unit: XmlNode, needWorkRules: string[]) : boolean {
function checkForNeedWorkTranslation(targetDocument: XlfDocument, unit: XmlNode, isRuleEnabled: (ruleName: string) => boolean) : boolean {
const sourceText = targetDocument.getUnitSourceText(unit);
const translText = targetDocument.getUnitTranslation(unit);
const devNoteText = targetDocument.getUnitDeveloperNote(unit) || '';
if (!sourceText || !translText) {
return false;
}

if (targetDocument.sourceLanguage === targetDocument.targetLanguage) {
if ((needWorkRules.indexOf('SourceEqualsTarget') >= 0) && sourceText !== translText) {
if (isRuleEnabled('SourceEqualsTarget') && sourceText !== translText) {
targetDocument.setXliffSyncNote(unit, 'Problem detected: The source text is not the same as the translation, but the source-language is the same as the target-language.');
return true;
}
}

if ((needWorkRules.indexOf('Placeholders') >= 0) && checkForPlaceHolderMismatch(sourceText, translText)) {
if (isRuleEnabled('Placeholders') && checkForPlaceHolderMismatch(sourceText, translText)) {
targetDocument.setXliffSyncNote(unit, 'Problem detected: The number of placeholders in the source and translation text do not match.');
return true;
}
if (isRuleEnabled('PlaceholdersDevNote') && checkForPlaceHolderMismatch(sourceText, devNoteText)) {
targetDocument.setXliffSyncNote(unit, 'Problem detected: One or more placeholders are missing an explanation in the Developer note.');
return true;
}

if (isOptionCaptionUnit(targetDocument, unit)) {
if ((needWorkRules.indexOf('OptionMemberCount') >= 0) && checkForOptionMemberCountMismatch(sourceText, translText)) {
if (isRuleEnabled('OptionMemberCount') && checkForOptionMemberCountMismatch(sourceText, translText)) {
targetDocument.setXliffSyncNote(unit, 'Problem detected: The number of option members in the source and translation text do not match.');
return true;
}
if ((needWorkRules.indexOf('OptionLeadingSpaces') >= 0) && checkForOptionMemberLeadingSpacesMismatch(sourceText, translText)) {
if (isRuleEnabled('OptionLeadingSpaces') && checkForOptionMemberLeadingSpacesMismatch(sourceText, translText)) {
targetDocument.setXliffSyncNote(unit, 'Problem detected: The leading spaces in the option values of the source and translation text do not match.');
return true;
}
}

if (needWorkRules.indexOf('ConsecutiveSpacesExist') >= 0) {
if (isRuleEnabled('ConsecutiveSpacesExist')) {
if (checkForConsecutiveSpaces(sourceText)) {
targetDocument.setXliffSyncNote(unit, 'Problem detected: Consecutive spaces exist in the source text.');
return true;
Expand All @@ -383,7 +394,7 @@ function checkForNeedWorkTranslation(targetDocument: XlfDocument, unit: XmlNode,
}
}

if (needWorkRules.indexOf('ConsecutiveSpacesConsistent') >= 0 && checkForConsecutiveSpacesInconsistency(sourceText, translText)) {
if (isRuleEnabled('ConsecutiveSpacesConsistent') && checkForConsecutiveSpacesInconsistency(sourceText, translText)) {
targetDocument.setXliffSyncNote(unit, 'Problem detected: The "consecutive space"-occurrences in source and translation text do not match.');
return true;
}
Expand Down

0 comments on commit 0d45561

Please sign in to comment.