| 22 | import {TranslationBundle} from './translation_bundle'; |
| 23 | |
| 24 | export 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 | |
| 69 | function createSerializer(format?: string): Serializer { |
| 70 | format = (format || 'xlf').toLowerCase(); |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…