MCPcopy Index your code
hub / github.com/angular/angular / I18NHtmlParser

Class I18NHtmlParser

packages/compiler/src/i18n/i18n_html_parser.ts:24–67  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

22import {TranslationBundle} from './translation_bundle';
23
24export class I18NHtmlParser implements HtmlParser {
25 // @override
26 getTagDefinition: any;
27
28 private _translationBundle: TranslationBundle;
29
30 constructor(
31 private _htmlParser: HtmlParser,
32 translations?: string,
33 translationsFormat?: string,
34 missingTranslation: MissingTranslationStrategy = MissingTranslationStrategy.Warning,
35 console?: Console,
36 ) {
37 if (translations) {
38 const serializer = createSerializer(translationsFormat);
39 this._translationBundle = TranslationBundle.load(
40 translations,
41 'i18n',
42 serializer,
43 missingTranslation,
44 console,
45 );
46 } else {
47 this._translationBundle = new TranslationBundle(
48 {},
49 null,
50 digest,
51 undefined,
52 missingTranslation,
53 console,
54 );
55 }
56 }
57
58 parse(source: string, url: string, options: TokenizeOptions = {}): ParseTreeResult {
59 const parseResult = this._htmlParser.parse(source, url, {...options});
60
61 if (parseResult.errors.length) {
62 return new ParseTreeResult(parseResult.rootNodes, parseResult.errors);
63 }
64
65 return mergeTranslations(parseResult.rootNodes, this._translationBundle, [], {});
66 }
67}
68
69function createSerializer(format?: string): Serializer {
70 format = (format || 'xlf').toLowerCase();

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…