Overview
Performs the same normalization asnormalizeTranslationText, but also returns an index map that tracks how each character in the normalized text corresponds to positions in the original input. This is useful for error reporting and debugging.
Function Signature
Parameters
Raw translation text that may contain inconsistent line endings or merged markers.
Returns
The normalized text with standardized line endings and properly separated markers.
Array where each index represents a character position in the normalized string, and the value at that index is the corresponding character position in the original input string.
Usage
Basic Example
Tracking Character Positions
Error Reporting with Position Mapping
What It Does
The function performs the same normalization steps asnormalizeTranslationText:
- Line Ending Normalization: Converts \r\n and \r to \n
- Merged Marker Splitting: Inserts newlines before markers merged with text
-
Escaped Bracket Handling: Removes backslash escaping from
\[
Understanding the Index Map
TheindexMap array has the same length as the normalized string. For any position i in the normalized string:
i in the normalized string.
Important: When characters are inserted during normalization (like newlines), multiple positions in the normalized string may map to the same original position.
When to Use
UsenormalizeTranslationTextWithMap when:
- You need to report errors with accurate original text positions
- Building developer tools or debuggers for translation processing
- Implementing syntax highlighting or error underlining in editors
- Debugging normalization issues by tracking character transformations
normalizeTranslationText function instead.
Related Functions
normalizeTranslationText- Simpler version without position mappingextractTranslationIds- Extract IDs from normalized textparseTranslations- Parse normalized text into translations