Skip to content

Commit

Permalink
doc: updated readme for up-to-date summary and changed defaults for f…
Browse files Browse the repository at this point in the history
…uture major version
  • Loading branch information
daniel-sc committed Nov 17, 2023
1 parent bdb592f commit d5175ff
Showing 1 changed file with 25 additions and 24 deletions.
49 changes: 25 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@

# Angular extract i18n and merge

This extends Angular CLI to improve the i18n extraction and merge workflow. New/removed translations are added/removed
from the target translation files. Additionally, translation files are normalized (pretty print, sorted by id) so that
diffs are easy to read (and translations in PRs might actually get reviewed ;-) ).
This extends Angular CLI to improve the i18n extraction and merge workflow.
New/removed translations are added/removed from the target translation files and translation states are managed.
Additionally, translation files are normalized (whitespace, stable sort) so that diffs are easy to read
(and translations in PRs might actually get reviewed ;-) ).

## Install

_Prerequisites_: i18n setup with defined target locales in `angular.json` - as
documented [here](https://angular.io/guide/i18n-common-merge).
documented [here](https://angular.dev/guide/i18n/merge).

```shell
ng add ng-extract-i18n-merge
Expand All @@ -38,26 +39,26 @@ ng extract-i18n # yes, same as before - this replaces the original builder

In your `angular.json` the target `extract-i18n` that can be configured with the following options:

| Name | Default | Description |
|------------------------------|-------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `browserTarget` | Inferred from current setup by `ng add` | A browser builder target to extract i18n messages in the format of `project:target[:configuration]`. See https://angular.io/cli/extract-i18n#options |
| `format` | Inferred from current setup by `ng add` | Any of `xlf`, `xlif`, `xliff`, `xlf2`, `xliff2` |
| `outputPath` | Inferred from current setup by `ng add` | Path to folder containing all (source and target) translation files. |
| `targetFiles` | Inferred from current setup by `ng add` | Filenames (relative to `outputPath` of all target translation files (e.g. `["messages.fr.xlf", "messages.de.xlf"]`). |
| `sourceLanguageTargetFile` | Unused | If this is set (to one of the `targetFiles`), new translations in that target file will be set to `state="final"` (instead of default `state="new"`). This file can be used to manage changes to the source texts: when a translator updates the target, this tool will hint the developer to update the code occurrences. |
| `sourceFile` | `messages.xlf`. `ng add` tries to infer non default setups. | Filename (relative to `outputPath` of source translation file (e.g. `"translations-source.xlf"`). |
| `removeIdsWithPrefix` | `[]` | List of prefix strings. All translation units with matching `id` attribute are removed. Useful for excluding duplicate library translations. Cannot be used in combination with `includeIdsWithPrefix`. |
| `includeIdsWithPrefix` | `[]` | List of prefix strings. when non-empty, only translations units with matching `id` are included. Useful for extracting translations of a single library in a multi-library project. Cannot be used in combination with `removeIdsWithPrefix`. |
| `fuzzyMatch` | `true` | Whether translation units without matching IDs are fuzzy matched by source text. |
| `resetTranslationState` | `true` | Reset the translation state to new/initial for new/changed units. |
| `prettyNestedTags` | `true` (will change to `false` with v3.0.0) | If source/target only contains xml nodes (interpolations, nested html), `true` formats these with line breaks and indentation. `false` keeps the original angular single line format. Note: while `true` was the historic implementation, it is _not_ recommended, as it adds whitespace between tags that had no whitespace in between and increases bundle sizes. |
| `collapseWhitespace` | `true` | Collapsing of multiple whitespaces/line breaks in translation sources and targets. |
| `trim` | `false` | Trim translation sources and targets. |
| `includeContext` | `false` | Whether to include the context information (like notes) in the translation files. This is useful for sending the target translation files to translation agencies/services. When `sourceFileOnly`, the context is retained only in the `sourceFile`. |
| `newTranslationTargetsBlank` | `false` | When `false` (default) the "target" of new translation units is set to the "source" value. When `true`, an empty string is used. When `'omit'`, no target element is created. |
| `sort` | `"stableAppendNew"` | Sorting of all translation units in source and target translation files. Supported: <br>`"idAsc"` (sort by translation IDs), <br>`"stableAppendNew"` (keep existing sorting, append new translations at the end), <br>`"stableAlphabetNew"` (keep existing sorting, sort new translations next to alphabetical close IDs) |
| `builderI18n` | `"@angular-devkit/build-angular:extract-i18n"` | The builder to use for i18n extraction. Any custom builder should handle the same options as the default angular builder (browserTarget, outputPath, outFile, format, progress). |
| `verbose` | `false` | Extended/debug output - it is recommended to use this only for manual debugging. |
| Name | Default | Description |
|------------------------------|----------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `browserTarget` | Inferred from current setup by `ng add` | A browser builder target to extract i18n messages in the format of `project:target[:configuration]`. See https://angular.io/cli/extract-i18n#options |
| `format` | Inferred from current setup by `ng add` | Any of `xlf`, `xlif`, `xliff`, `xlf2`, `xliff2` |
| `outputPath` | Inferred from current setup by `ng add` | Path to folder containing all (source and target) translation files. |
| `targetFiles` | Inferred from current setup by `ng add` | Filenames (relative to `outputPath` of all target translation files (e.g. `["messages.fr.xlf", "messages.de.xlf"]`). |
| `sourceLanguageTargetFile` | Unused | If this is set (to one of the `targetFiles`), new translations in that target file will be set to `state="final"` (instead of default `state="new"`). This file can be used to manage changes to the source texts: when a translator updates the target, this tool will hint the developer to update the code occurrences. |
| `sourceFile` | `messages.xlf`. `ng add` tries to infer non default setups. | Filename (relative to `outputPath` of source translation file (e.g. `"translations-source.xlf"`). |
| `removeIdsWithPrefix` | `[]` | List of prefix strings. All translation units with matching `id` attribute are removed. Useful for excluding duplicate library translations. Cannot be used in combination with `includeIdsWithPrefix`. |
| `includeIdsWithPrefix` | `[]` | List of prefix strings. When non-empty, only translations units with matching `id` are included. Useful for extracting translations of a single library in a multi-library project. Cannot be used in combination with `removeIdsWithPrefix`. |
| `fuzzyMatch` | `true` | Whether translation units without matching IDs are fuzzy matched by source text. |
| `resetTranslationState` | `true` | Reset the translation state to new/initial for new/changed units. |
| `prettyNestedTags` | `true` (will change to `false` with v3.0.0) | If source/target only contains xml nodes (interpolations, nested html), `true` formats these with line breaks and indentation. `false` keeps the original angular single line format. Note: while `true` was the historic implementation, it is _not_ recommended, as it adds whitespace between tags that had no whitespace in between and increases bundle sizes. |
| `collapseWhitespace` | `true` | Collapsing of multiple whitespaces/line breaks in translation sources and targets. |
| `trim` | `false` | Trim translation sources and targets. |
| `includeContext` | `false` | Whether to include the context information (like notes) in the translation files. This is useful for sending the target translation files to translation agencies/services. When `sourceFileOnly`, the context is retained only in the `sourceFile`. |
| `newTranslationTargetsBlank` | `false` | When `false` (default) the "target" of new translation units is set to the "source" value. When `true`, an empty string is used. When `'omit'`, no target element is created. |
| `sort` | `"stableAppendNew"` (will change to `stableAlphabetNew` with v3.0.0) | Sorting of all translation units in source and target translation files. Supported: <br>`"idAsc"` (sort by translation IDs), <br>`"stableAppendNew"` (keep existing sorting, append new translations at the end), <br>`"stableAlphabetNew"` (keep existing sorting, sort new translations next to alphabetical close IDs). |
| `builderI18n` | `"@angular-devkit/build-angular:extract-i18n"` | The builder to use for i18n extraction. Any custom builder should handle the same options as the default angular builder (browserTarget, outputPath, outFile, format, progress). |
| `verbose` | `false` | Extended/debug output - it is recommended to use this only for manual debugging. |

## Contribute

Expand Down

0 comments on commit d5175ff

Please sign in to comment.