working translator
by Eugen Sunic
JavaScript
import { Observable } from 'rxjs/Rx';
import { TranslateLoader } from '@ngx-translate/core';
import { HttpClient } from '@angular/common/http';
/*
Loader loads resource from a specified path on the server. It uses HttpClient get method
to request a resource. In HttpClient get() we can place any path to fetch the data from it.
For now, Loader loads only labels.json. For other resources, we can dinamically use getTranslation(lang:string)
in order to fetch our desired file form the server.
*/
export class CustomTranslateLoader implements TranslateLoader {
labelsPath;
webHostUrl;
constructor(private http: HttpClient) { this.webHostUrl = localStorage.getItem('taxes-web-host'); }
public getTranslation(lang: string): Observable<any> {
if (localStorage.getItem('preview_mode') === null) {
console.log('Is NOT in preview mode: ' + this.webHostUrl);
if (this.webHostUrl === null || this.webHostUrl.indexOf('localhost') !== -1) {
console.log('Is CMS CONFIGURABLE is local or null: ' + this.webHostUrl);
this.labelsPath = '';
} else {
this.labelsPath = this.webHostUrl;
console.log('Is CMS CONFIGURABLE has completely changed: labels values ' + this.labelsPath);
}
//return this.http.get(this.labelsP);
return this.getRequestConfigure(this.labelsPath, '/web/web-taxes/', lang, '.json');
} else {
console.log('Is INSIDE preview mode: ' + this.webHostUrl);
return this.getRequestConfigure('https://int-acc-fut-evcms.consorsbank.de:442',
'/content/cortalconsors_de_cc/library/Mein-Konto-und-Depot/Steuer/',
'labels.pageGrid',
'html?wcmmode=disabled');
}
}
private getRequestConfigure(host: string, subpath: string, lang: string, format: string): Observable<any> {
console.log("host is: "+ host)
return this.http.get(host.concat(subpath, lang, format));
}
}