{"version":3,"file":"transla-x.mjs","sources":["../../../projects/transla-x/src/lib/transla-x.service.ts","../../../projects/transla-x/src/lib/transla-x.pipe.ts","../../../projects/transla-x/src/lib/transla-x.interceptor.ts","../../../projects/transla-x/src/lib/transla-x.module.ts","../../../projects/transla-x/src/public-api.ts","../../../projects/transla-x/src/transla-x.ts"],"sourcesContent":["import { Injectable } from '@angular/core';\nimport { HttpClient } from '@angular/common/http';\nimport { TranslaXConfig } from './transla-x.interface';\n\n@Injectable({\n  providedIn: 'root'\n})\nexport class TranslaXService {\n  private translations: { [key: string]: any } = {};\n  private supportedLanguages: string[] = [];\n\n  constructor(private http: HttpClient) {}\n\n  configure(config: TranslaXConfig): void {\n    this.supportedLanguages = config.supportedLanguages;\n  }\n\n  getSupportedLanguages(): string[] {\n    return this.supportedLanguages;\n  }\n\n  loadTranslations(language: string): Promise<any> {\n    const translationFile = `/assets/i18n/${language}.json`;\n\n    return this.http\n      .get(translationFile)\n      .toPromise()\n      .then((translations: any) => {\n        this.translations[language] = translations;\n      })\n      .catch((error: any) => {\n        console.error(`Failed to load translations for language '${language}'`, error);\n      });\n  }\n\n  getTranslation(key: string, language: string): string {\n    const translations = this.translations[language];\n\n    if (translations && translations[key]) {\n      return translations[key];\n    }\n\n    return '';\n  }\n}\n","\r\nimport { Pipe, PipeTransform } from '@angular/core';\r\nimport { TranslaXService } from './transla-x.service';\r\n\r\n@Pipe({\r\n  name: 'translation'\r\n})\r\nexport class TranslaXPipe implements PipeTransform {\r\n  constructor(private translateX: TranslaXService) {}\r\n\r\n  transform(value: string, language: string): string {\r\n    const translation = this.translateX.getTranslation(value, language);\r\n    return translation || value;\r\n  }\r\n}\r\n","import { Injectable } from '@angular/core';\r\nimport {\r\n  HttpEvent,\r\n  HttpHandler,\r\n  HttpInterceptor,\r\n  HttpRequest\r\n} from '@angular/common/http';\r\nimport { Observable } from 'rxjs';\r\nimport { finalize } from 'rxjs/operators';\r\nimport { TranslaXService } from './transla-x.service';\r\n\r\n@Injectable()\r\nexport class TranslaXInterceptor implements HttpInterceptor {\r\n  constructor(private translateX: TranslaXService) {}\r\n\r\n  intercept(\r\n    req: HttpRequest<any>,\r\n    next: HttpHandler\r\n  ): Observable<HttpEvent<any>> {\r\n    const languages = this.translateX.getSupportedLanguages();\r\n\r\n    return next.handle(req).pipe(\r\n      finalize(() => {\r\n        const promises: Promise<any>[] = languages.map((language: string) =>\r\n          this.translateX.loadTranslations(language).catch((error: any) => {\r\n            console.error(`Failed to load translations for language '${language}'`, error);\r\n          })\r\n        );\r\n\r\n        Promise.all(promises)\r\n          .then(() => {\r\n            // Translations are loaded for all languages\r\n          })\r\n          .catch((error: any) => {\r\n            console.error('Failed to load translations', error);\r\n          });\r\n      })\r\n    );\r\n  }\r\n}\r\n","import { NgModule, ModuleWithProviders } from '@angular/core';\nimport { HttpClientModule, HTTP_INTERCEPTORS } from '@angular/common/http';\nimport { TranslaXInterceptor } from './transla-x.interceptor';\nimport { TranslaXPipe } from './transla-x.pipe';\nimport { TranslaXConfig } from './transla-x.interface';\nimport { TranslaXService } from './transla-x.service';\n\n@NgModule({\n  declarations: [TranslaXPipe],\n  imports: [HttpClientModule],\n  exports: [TranslaXPipe]\n})\nexport class TranslaXModule {\n  static forRoot(config: TranslaXConfig): ModuleWithProviders<TranslaXModule> {\n    return {\n      ngModule: TranslaXModule,\n      providers: [\n        TranslaXService,\n        {\n          provide: HTTP_INTERCEPTORS,\n          useClass: TranslaXInterceptor,\n          multi: true\n        },\n        { provide: 'TRANSLAX_CONFIG', useValue: config }\n      ]\n    };\n  }\n}\n","/*\n * Public API Surface of transla-x\n */\n\nexport * from './lib/transla-x.service';\nexport * from './lib/transla-x.pipe';\nexport * from './lib/transla-x.interceptor';\nexport * from './lib/transla-x.interface';\nexport * from './lib/transla-x.module';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":["i1.TranslaXService"],"mappings":";;;;;;MAOa,eAAe,CAAA;AAI1B,IAAA,WAAA,CAAo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