angular-l10n
Version:
An Angular library to translate messages, dates and numbers
84 lines • 2.68 kB
JavaScript
/**
* @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';
var L10nJsonLdComponent = /** @class */ (function () {
function L10nJsonLdComponent(translation, sanitizer) {
this.translation = translation;
this.sanitizer = sanitizer;
this.destroy = new Subject();
}
/**
* @return {?}
*/
L10nJsonLdComponent.prototype.ngOnInit = /**
* @return {?}
*/
function () {
var _this = this;
this.translation.translationChanged().pipe(takeUntil(this.destroy)).subscribe(function () {
/** @type {?} */
var schema = _this.translation.translate(_this.path);
_this.jsonLD = schema ? _this.sanitize(schema) : "";
});
};
/**
* @return {?}
*/
L10nJsonLdComponent.prototype.ngOnDestroy = /**
* @return {?}
*/
function () {
this.destroy.next(true);
};
/**
* @param {?} schema
* @return {?}
*/
L10nJsonLdComponent.prototype.sanitize = /**
* @param {?} schema
* @return {?}
*/
function (schema) {
/** @type {?} */
var json = JSON.stringify(schema, null, 2);
/** @type {?} */
var 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 = function () { return [
{ type: TranslationService },
{ type: DomSanitizer }
]; };
L10nJsonLdComponent.propDecorators = {
path: [{ type: Input }],
jsonLD: [{ type: HostBinding, args: ['innerHTML',] }]
};
return L10nJsonLdComponent;
}());
export { L10nJsonLdComponent };
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