UNPKG

angular-l10n

Version:

An Angular library to translate messages, dates and numbers

75 lines 2.27 kB
/** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,uselessCode} checked by tsc */ import { Component, Input, HostBinding } from '@angular/core'; import { DomSanitizer } from '@angular/platform-browser'; import { Subject } from 'rxjs'; import { takeUntil } from 'rxjs/operators'; import { TranslationService } from '../services/translation.service'; export class L10nJsonLdComponent { /** * @param {?} translation * @param {?} sanitizer */ constructor(translation, sanitizer) { this.translation = translation; this.sanitizer = sanitizer; this.destroy = new Subject(); } /** * @return {?} */ ngOnInit() { this.translation.translationChanged().pipe(takeUntil(this.destroy)).subscribe(() => { /** @type {?} */ const schema = this.translation.translate(this.path); this.jsonLD = schema ? this.sanitize(schema) : ""; }); } /** * @return {?} */ ngOnDestroy() { this.destroy.next(true); } /** * @param {?} schema * @return {?} */ sanitize(schema) { /** @type {?} */ const json = JSON.stringify(schema, null, 2); /** @type {?} */ const html = `<script type="application/ld+json">${json}</script>`; return this.sanitizer.bypassSecurityTrustHtml(html); } } L10nJsonLdComponent.decorators = [ { type: Component, args: [{ selector: 'l10n-json-ld', template: '' }] } ]; /** @nocollapse */ L10nJsonLdComponent.ctorParameters = () => [ { type: TranslationService }, { type: DomSanitizer } ]; L10nJsonLdComponent.propDecorators = { path: [{ type: Input }], jsonLD: [{ type: HostBinding, args: ['innerHTML',] }] }; if (false) { /** @type {?} */ L10nJsonLdComponent.prototype.path; /** @type {?} */ L10nJsonLdComponent.prototype.jsonLD; /** @type {?} */ L10nJsonLdComponent.prototype.destroy; /** @type {?} */ L10nJsonLdComponent.prototype.translation; /** @type {?} */ L10nJsonLdComponent.prototype.sanitizer; } //# sourceMappingURL=l10n-json-ld.component.js.map