diff --git a/packages/localize/src/tools/src/translate/translation_files/translation_parsers/i18n_error.ts b/packages/localize/src/tools/src/translate/translation_files/translation_parsers/translation_parse_error.ts similarity index 84% rename from packages/localize/src/tools/src/translate/translation_files/translation_parsers/i18n_error.ts rename to packages/localize/src/tools/src/translate/translation_files/translation_parsers/translation_parse_error.ts index dc5c7d378b..beec87a8d2 100644 --- a/packages/localize/src/tools/src/translate/translation_files/translation_parsers/i18n_error.ts +++ b/packages/localize/src/tools/src/translate/translation_files/translation_parsers/translation_parse_error.ts @@ -8,10 +8,9 @@ import {ParseErrorLevel, ParseSourceSpan} from '@angular/compiler'; /** - * Instances of this class are thrown when there is an error in the source code that is being - * translated. + * This error is thrown when there is a problem parsing a translation file. */ -export class I18nError extends Error { +export class TranslationParseError extends Error { constructor( public span: ParseSourceSpan, public msg: string, public level: ParseErrorLevel = ParseErrorLevel.ERROR) { diff --git a/packages/localize/src/tools/src/translate/translation_files/translation_parsers/translation_utils.ts b/packages/localize/src/tools/src/translate/translation_files/translation_parsers/translation_utils.ts index 9d707f0886..5daafe701b 100644 --- a/packages/localize/src/tools/src/translate/translation_files/translation_parsers/translation_utils.ts +++ b/packages/localize/src/tools/src/translate/translation_files/translation_parsers/translation_utils.ts @@ -6,12 +6,13 @@ * found in the LICENSE file at https://angular.io/license */ import {Element, LexerRange, Node, XmlParser} from '@angular/compiler'; -import {I18nError} from './i18n_error'; +import {TranslationParseError} from './translation_parse_error'; export function getAttrOrThrow(element: Element, attrName: string): string { const attrValue = getAttribute(element, attrName); if (attrValue === undefined) { - throw new I18nError(element.sourceSpan, `Missing required "${attrName}" attribute:`); + throw new TranslationParseError( + element.sourceSpan, `Missing required "${attrName}" attribute:`); } return attrValue; } diff --git a/packages/localize/src/tools/src/translate/translation_files/translation_parsers/xliff1/xliff1_message_serializer.ts b/packages/localize/src/tools/src/translate/translation_files/translation_parsers/xliff1/xliff1_message_serializer.ts index 5b9e9fb369..2824c78081 100644 --- a/packages/localize/src/tools/src/translate/translation_files/translation_parsers/xliff1/xliff1_message_serializer.ts +++ b/packages/localize/src/tools/src/translate/translation_files/translation_parsers/xliff1/xliff1_message_serializer.ts @@ -8,7 +8,7 @@ import {Element, Expansion, ExpansionCase, Node, Text, visitAll} from '@angular/compiler'; import {MessageRenderer} from '../../../message_renderers/message_renderer'; import {BaseVisitor} from '../base_visitor'; -import {I18nError} from '../i18n_error'; +import {TranslationParseError} from '../translation_parse_error'; import {getAttrOrThrow} from '../translation_utils'; const INLINE_ELEMENTS = ['g', 'bx', 'ex', 'bpt', 'ept', 'ph', 'it', 'mrk']; @@ -29,7 +29,7 @@ export class Xliff1MessageSerializer extends BaseVisitor { } else if (INLINE_ELEMENTS.indexOf(element.name) !== -1) { visitAll(this, element.children); } else { - throw new I18nError(element.sourceSpan, `Invalid element found in message.`); + throw new TranslationParseError(element.sourceSpan, `Invalid element found in message.`); } } diff --git a/packages/localize/src/tools/src/translate/translation_files/translation_parsers/xliff1/xliff1_translation_parser.ts b/packages/localize/src/tools/src/translate/translation_files/translation_parsers/xliff1/xliff1_translation_parser.ts index 93350b9ea3..7679f61801 100644 --- a/packages/localize/src/tools/src/translate/translation_files/translation_parsers/xliff1/xliff1_translation_parser.ts +++ b/packages/localize/src/tools/src/translate/translation_files/translation_parsers/xliff1/xliff1_translation_parser.ts @@ -11,7 +11,7 @@ import {extname} from 'path'; import {TargetMessageRenderer} from '../../../message_renderers/target_message_renderer'; import {TranslationBundle} from '../../../translator'; import {BaseVisitor} from '../base_visitor'; -import {I18nError} from '../i18n_error'; +import {TranslationParseError} from '../translation_parse_error'; import {TranslationParser} from '../translation_parser'; import {getAttrOrThrow, parseInnerRange} from '../translation_utils'; import {Xliff1MessageSerializer} from './xliff1_message_serializer'; @@ -75,12 +75,13 @@ class XliffTranslationVisitor extends BaseVisitor { if (element.name === 'trans-unit') { const id = getAttrOrThrow(element, 'id'); if (this.translations[id] !== undefined) { - throw new I18nError(element.sourceSpan, `Duplicated translations for message "${id}"`); + throw new TranslationParseError( + element.sourceSpan, `Duplicated translations for message "${id}"`); } const targetMessage = element.children.find(isTargetElement); if (targetMessage === undefined) { - throw new I18nError(element.sourceSpan, 'Missing required element'); + throw new TranslationParseError(element.sourceSpan, 'Missing required element'); } this.translations[id] = serializeTargetMessage(targetMessage); } else { diff --git a/packages/localize/src/tools/src/translate/translation_files/translation_parsers/xliff2/xliff2_message_serializer.ts b/packages/localize/src/tools/src/translate/translation_files/translation_parsers/xliff2/xliff2_message_serializer.ts index 6f2d93379d..0545cf2f79 100644 --- a/packages/localize/src/tools/src/translate/translation_files/translation_parsers/xliff2/xliff2_message_serializer.ts +++ b/packages/localize/src/tools/src/translate/translation_files/translation_parsers/xliff2/xliff2_message_serializer.ts @@ -8,7 +8,7 @@ import {Element, Expansion, ExpansionCase, Node, Text, visitAll} from '@angular/compiler'; import {MessageRenderer} from '../../../message_renderers/message_renderer'; import {BaseVisitor} from '../base_visitor'; -import {I18nError} from '../i18n_error'; +import {TranslationParseError} from '../translation_parse_error'; import {getAttrOrThrow, getAttribute} from '../translation_utils'; const INLINE_ELEMENTS = ['cp', 'sc', 'ec', 'mrk', 'sm', 'em']; @@ -33,7 +33,7 @@ export class Xliff2MessageSerializer extends BaseVisitor { } else if (INLINE_ELEMENTS.indexOf(element.name) !== -1) { visitAll(this, element.children); } else { - throw new I18nError(element.sourceSpan, `Invalid element found in message.`); + throw new TranslationParseError(element.sourceSpan, `Invalid element found in message.`); } } diff --git a/packages/localize/src/tools/src/translate/translation_files/translation_parsers/xliff2/xliff2_translation_parser.ts b/packages/localize/src/tools/src/translate/translation_files/translation_parsers/xliff2/xliff2_translation_parser.ts index 65736b6395..6167c9fcac 100644 --- a/packages/localize/src/tools/src/translate/translation_files/translation_parsers/xliff2/xliff2_translation_parser.ts +++ b/packages/localize/src/tools/src/translate/translation_files/translation_parsers/xliff2/xliff2_translation_parser.ts @@ -11,7 +11,7 @@ import {extname} from 'path'; import {TargetMessageRenderer} from '../../../message_renderers/target_message_renderer'; import {TranslationBundle} from '../../../translator'; import {BaseVisitor} from '../base_visitor'; -import {I18nError} from '../i18n_error'; +import {TranslationParseError} from '../translation_parse_error'; import {TranslationParser} from '../translation_parser'; import {getAttrOrThrow, parseInnerRange} from '../translation_utils'; import {Xliff2MessageSerializer} from './xliff2_message_serializer'; @@ -78,7 +78,7 @@ class Xliff2TranslationVisitor extends BaseVisitor { if (element.name === 'unit') { const externalId = getAttrOrThrow(element, 'id'); if (this.translations[externalId] !== undefined) { - throw new I18nError( + throw new TranslationParseError( element.sourceSpan, `Duplicated translations for message "${externalId}"`); } visitAll(this, element.children, {unit: externalId}); @@ -86,7 +86,7 @@ class Xliff2TranslationVisitor extends BaseVisitor { assertTranslationUnit(element, context); const targetMessage = element.children.find(isTargetElement); if (targetMessage === undefined) { - throw new I18nError(element.sourceSpan, 'Missing required element'); + throw new TranslationParseError(element.sourceSpan, 'Missing required element'); } this.translations[context.unit] = serializeTargetMessage(targetMessage); } else { @@ -97,7 +97,7 @@ class Xliff2TranslationVisitor extends BaseVisitor { function assertTranslationUnit(segment: Element, context: any) { if (context === undefined || context.unit === undefined) { - throw new I18nError( + throw new TranslationParseError( segment.sourceSpan, 'Invalid element: should be a child of a element.'); } }