forked from angular/angular
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(localize): render context of translation file parse errors (angul…
…ar#38673) Previously the position of the error in a translation file when parsing it was not displayed. Just the error message. Now the position (line and column) and some context is displayed along with the error messages. Fixes angular#38377 PR Close angular#38673
- Loading branch information
1 parent
696d8ba
commit f063fe3
Showing
10 changed files
with
140 additions
and
115 deletions.
There are no files selected for viewing
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
32 changes: 32 additions & 0 deletions
32
...ools/src/translate/translation_files/translation_parsers/serialize_translation_message.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,32 @@ | ||
/** | ||
* @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 {Element, ParseError} from '@angular/compiler'; | ||
import {ɵParsedTranslation} from '@angular/localize'; | ||
|
||
import {MessageSerializer, MessageSerializerConfig} from '../message_serialization/message_serializer'; | ||
import {TargetMessageRenderer} from '../message_serialization/target_message_renderer'; | ||
|
||
import {parseInnerRange} from './translation_utils'; | ||
|
||
/** | ||
* Serialize the given `element` into a parsed translation using the given `serializer`. | ||
*/ | ||
export function serializeTranslationMessage(element: Element, config: MessageSerializerConfig): { | ||
translation: ɵParsedTranslation|null, | ||
parseErrors: ParseError[], | ||
serializeErrors: ParseError[] | ||
} { | ||
const {rootNodes, errors: parseErrors} = parseInnerRange(element); | ||
try { | ||
const serializer = new MessageSerializer(new TargetMessageRenderer(), config); | ||
const translation = serializer.serialize(rootNodes); | ||
return {translation, parseErrors, serializeErrors: []}; | ||
} catch (e) { | ||
return {translation: null, parseErrors, serializeErrors: [e]}; | ||
} | ||
} |
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
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
Oops, something went wrong.