Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(localize): serialize all the message locations to XLIFF (#39411)
Previously only the first message, for each id, was serialized which meant that additional message location information was lost. Now all the message locations are included in the serialized messages. Fixes #39330 PR Close #39411
- Loading branch information
1 parent
e8e3771
commit f5710c6
Showing
5 changed files
with
237 additions
and
21 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
packages/localize/src/tools/src/extract/translation_files/utils.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/** | ||
* @license | ||
* Copyright Google LLC All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
import {ɵMessageId, ɵParsedMessage, ɵSourceLocation} from '@angular/localize'; | ||
|
||
/** | ||
* Consolidate an array of messages into a map from message id to an array of messages with that id. | ||
* | ||
* @param messages the messages to consolidate. | ||
* @param getMessageId a function that will compute the message id of a message. | ||
*/ | ||
export function consolidateMessages( | ||
messages: ɵParsedMessage[], | ||
getMessageId: (message: ɵParsedMessage) => string): Map<ɵMessageId, ɵParsedMessage[]> { | ||
const consolidateMessages = new Map<ɵMessageId, ɵParsedMessage[]>(); | ||
for (const message of messages) { | ||
const id = getMessageId(message); | ||
if (!consolidateMessages.has(id)) { | ||
consolidateMessages.set(id, [message]); | ||
} else { | ||
consolidateMessages.get(id)!.push(message); | ||
} | ||
} | ||
return consolidateMessages; | ||
} | ||
|
||
/** | ||
* Does the given message have a location property? | ||
*/ | ||
export function hasLocation(message: ɵParsedMessage): message is ɵParsedMessage& | ||
{location: ɵSourceLocation} { | ||
return message.location !== undefined; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters