You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
57 lines
1.3 KiB
TypeScript
57 lines
1.3 KiB
TypeScript
import { HttpClient } from '@angular/common/http';
|
|
import { Injectable } from '@angular/core';
|
|
import { ProvidersService } from '../providers.service';
|
|
|
|
|
|
/**************************
|
|
Created by Ajith A Pradeep
|
|
Created on 21/03/2022
|
|
**************************/
|
|
|
|
@Injectable({
|
|
providedIn: 'root'
|
|
})
|
|
export class ErrorTranslateService {
|
|
|
|
helpPrimaryData: any = {};
|
|
helpSecondaryData: any = {};
|
|
|
|
environment: any;
|
|
primaryLangauge: any="en";
|
|
|
|
constructor(
|
|
private httpClient: HttpClient,
|
|
private conn: ProvidersService
|
|
) {
|
|
this.environment = this.conn.environment;
|
|
this.init();
|
|
}
|
|
|
|
async init() {
|
|
await this.getPrimarySecondryLangauge();
|
|
}
|
|
|
|
async getPrimarySecondryLangauge(): Promise<void> {
|
|
this.helpPrimaryData = await this.getErrorJsonData(this.primaryLangauge);
|
|
}
|
|
|
|
translate(code: string): string {
|
|
return this.first(code) ;
|
|
}
|
|
|
|
first(code: string): string {
|
|
switch (this.primaryLangauge) {
|
|
case "": return;
|
|
default:
|
|
return this.helpPrimaryData[code] ? (this.helpPrimaryData[code]) : code;
|
|
}
|
|
}
|
|
|
|
|
|
private async getErrorJsonData(lang: string): Promise<any> {
|
|
if (!lang || lang.trim() == "") return {};
|
|
return await this.httpClient.get(`assets/i18n/error/${lang}.json`).toPromise();
|
|
}
|
|
|
|
}
|