Skip to content

Commit

Permalink
feat: Allow absolute paths for NAB.TranslationSuggestionPaths (#455)
Browse files Browse the repository at this point in the history
  • Loading branch information
MODUSCarstenScholling committed Feb 29, 2024
1 parent 9f84836 commit 607c824
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
2 changes: 2 additions & 0 deletions extension/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how
- Fixes:
- Added support for captions in the `layout` of a `rendering` section in reports. Thanks to [lv-janpieter](https://github.com/lv-janpieter) for bringing us the attention to this in [issue 441](https://github.com/jwikman/nab-al-tools/issues/441).
- Removed a couple of semicolons from the test snippets (see [this post on X](https://twitter.com/arthrvdv/status/1727729430737342791) for more information)
- Changes:
- Setting `NAB.TranslationSuggestionPaths` now supports absolute paths in addition to relative paths.

## [1.32]

Expand Down
2 changes: 1 addition & 1 deletion extension/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@ This extension contributes the following settings:
- `NAB.DetectInvalidTargets`: Enables detection of some common translation mistakes. Eg. same number of OptionCaptions, blank OptionCaptions and placeholders as `@1@@@@@@`, `#2########`, `%1`, `%2` etc . The detection will occur during several different actions, as Import from DTS or Refresh Xlf. This setting is enabled by default. If any false positives are detected (the system says it is invalid, but in fact it is correct), please log an issue on GitHub and disable this feature until it's fixed.
- `NAB.MatchTranslation`: If enabled, the `NAB: Refresh XLF files from g.xlf` function tries to match sources in the translated xlf file to reuse translations. A found match of "source" is then prefixed with `[NAB: SUGGESTION]` for manual review. If several matches are found, all matches are added as targets and you need delete the ones you do not want. Use `NAB: Find next untranslated text` (Ctrl+Alt+U) or `NAB: Find multiple targets in XLF files` to review all matches. This feature only works if "UseExternalTranslationTool" is disabled. Activated by default.
- `NAB.MatchBaseAppTranslation`: If enabled, the `NAB: Refresh XLF files from g.xlf` function tries to match sources in the translated xlf file with translations from the BaseApplication. A found match of `source` is then prefixed with [NAB: SUGGESTION] for manual review. If several matches are found, all matches are added and you need delete the ones you do not want. Use `NAB: Find next untranslated text` (Ctrl+Alt+U) or `NAB: Find multiple targets in XLF files` to review all matches. This feature only works if `UseExternalTranslationTool` is disabled. Disabled by default.
- `NAB.TranslationSuggestionPaths`: Supply any relative paths that contains xlf files that should be used when matching translations. The `NAB: Refresh XLF files from g.xlf` function will try to match any untranslated targets with targets in the xlf files in the provided folders that has matching target language.
- `NAB.TranslationSuggestionPaths`: Supply any relative or absolute paths that contains xlf files that should be used when matching translations. The `NAB: Refresh XLF files from g.xlf` function will try to match any untranslated targets with targets in the xlf files in the provided folders that has matching target language.
- `NAB.ShowXlfHighlights`: If enabled, all translation tags ([NAB: NOT TRANSLATED], [NAB: REVIEW] and [NAB: SUGGESTION]) will be highlighted ([Request 75](https://github.com/jwikman/nab-al-tools/issues/75)). Some common issues when writing targets manually is highlighted. Details found in [issue 71](https://github.com/jwikman/nab-al-tools/issues/71). Uses the style specified in `NAB.XlfHighlightsDecoration`.
- `NAB.XlfHighlightsDecoration`: Specifies the style that should be used to highlight inside xlf files.
- `NAB.UseExternalTranslationTool`: Modifies the state-attribute of the translation unit when running `NAB: Refresh XLF files from g.xlf` instead of inserting a searchable string. Useful when working with external translation software.
Expand Down
2 changes: 1 addition & 1 deletion extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@
},
"NAB.TranslationSuggestionPaths": {
"type": "array",
"description": "Supply any relative paths that contains xlf files that should be used when matching translations. The \"NAB: Refresh XLF files from g.xlf\" function will try to match any untranslated targets with targets in the xlf files in the provided folders that has matching target language.",
"description": "Supply any relative or absolute paths that contains xlf files that should be used when matching translations. The \"NAB: Refresh XLF files from g.xlf\" function will try to match any untranslated targets with targets in the xlf files in the provided folders that has matching target language.",
"scope": "resource"
},
"NAB.ShowXlfHighlights": {
Expand Down
15 changes: 8 additions & 7 deletions extension/src/XliffFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -567,15 +567,16 @@ export async function createSuggestionMaps(
}
// Any configured translation paths
languageFunctionsSettings.translationSuggestionPaths.forEach(
(relFolderPath) => {
const xlfFolderPath = path.join(
settings.workspaceFolderPath,
relFolderPath
);
fs.readdirSync(xlfFolderPath)
(relativeOrAbsoluteFolderPath) => {
const absoluteXlfFolderPath = path.isAbsolute(
relativeOrAbsoluteFolderPath
)
? relativeOrAbsoluteFolderPath
: path.join(settings.workspaceFolderPath, relativeOrAbsoluteFolderPath);
fs.readdirSync(absoluteXlfFolderPath)
.filter((item) => item.endsWith(".xlf") && !item.endsWith("g.xlf"))
.forEach((fileName) => {
const filePath = path.join(xlfFolderPath, fileName);
const filePath = path.join(absoluteXlfFolderPath, fileName);
addXliffToSuggestionMap(languageCodes, suggestionMaps, filePath);
});
}
Expand Down

0 comments on commit 607c824

Please sign in to comment.