{ "version": 3, "sources": ["src/app/core/i18n/language.service.ts"], "sourcesContent": ["import {startWith, shareReplay} from 'rxjs/operators';\nimport {Injectable} from '@angular/core';\nimport {BehaviorSubject, Observable} from 'rxjs';\nimport {AvailableLang} from '@discover-swiss/models';\n\nconst DEFAULT_LANG = 'de';\nconst LOCAL_STORAGE_LANG_KEY = 'currentLang';\n\n@Injectable({\n providedIn: 'root',\n})\nexport class LanguageService {\n private _langSource: BehaviorSubject;\n public languageChange$: Observable;\n public availableLang = ['en', 'de', 'fr', 'it'];\n\n constructor() {\n const storedLang = localStorage.getItem(\n LOCAL_STORAGE_LANG_KEY\n ) as AvailableLang;\n const browserLang =\n storedLang ?? (this.getBrowserLang() as AvailableLang);\n const useLang = browserLang.match(/en|de|fr|it/) ? browserLang : DEFAULT_LANG;\n this._langSource = new BehaviorSubject(useLang);\n this.languageChange$ = this._langSource\n .asObservable()\n .pipe(startWith(useLang), shareReplay(1));\n }\n\n public use(lang: AvailableLang): void {\n localStorage.setItem(LOCAL_STORAGE_LANG_KEY, lang);\n this._langSource.next(lang);\n }\n\n get currentLang(): AvailableLang {\n return this._langSource.getValue();\n }\n\n public getBrowserLang(): string {\n if (\n typeof window === 'undefined' ||\n typeof window.navigator === 'undefined'\n ) {\n return undefined;\n }\n let browserLang = window.navigator.languages\n ? window.navigator.languages[0]\n : null;\n browserLang =\n browserLang ||\n window.navigator.language ||\n (window.navigator as any).browserLanguage ||\n (window.navigator as any).userLanguage;\n if (typeof browserLang === 'undefined') {\n return undefined;\n }\n if (browserLang.indexOf('-') !== -1) {\n browserLang = browserLang.split('-')[0];\n }\n if (browserLang.indexOf('_') !== -1) {\n browserLang = browserLang.split('_')[0];\n }\n return browserLang;\n }\n}\n"], "mappings": "6DAKA,IAAMA,EAAe,KACfC,EAAyB,cAKlBC,GAAe,IAAA,CAAtB,MAAOA,CAAe,CAKxBC,aAAA,CAFO,KAAAC,cAAgB,CAAC,KAAM,KAAM,KAAM,IAAI,EAM1C,IAAMC,EAHaC,aAAaC,QAC5BN,CAAsB,GAGP,KAAKO,eAAc,EAChCC,EAAUJ,EAAYK,MAAM,aAAa,EAAIL,EAAcL,EACjE,KAAKW,YAAc,IAAIC,EAA+BH,CAAO,EAC7D,KAAKI,gBAAkB,KAAKF,YACvBG,aAAY,EACZC,KAAKC,EAAUP,CAAO,EAAGQ,EAAY,CAAC,CAAC,CAChD,CAEOC,IAAIC,EAAmB,CAC1Bb,aAAac,QAAQnB,EAAwBkB,CAAI,EACjD,KAAKR,YAAYU,KAAKF,CAAI,CAC9B,CAEA,IAAIG,aAAW,CACX,OAAO,KAAKX,YAAYY,SAAQ,CACpC,CAEOf,gBAAc,CACjB,GACI,OAAOgB,OAAW,KAClB,OAAOA,OAAOC,UAAc,IAE5B,OAEJ,IAAIpB,EAAcmB,OAAOC,UAAUC,UAC7BF,OAAOC,UAAUC,UAAU,CAAC,EAC5B,KAMN,GALArB,EACIA,GACAmB,OAAOC,UAAUE,UAChBH,OAAOC,UAAkBG,iBACzBJ,OAAOC,UAAkBI,aAC1B,SAAOxB,EAAgB,KAG3B,OAAIA,EAAYyB,QAAQ,GAAG,IAAM,KAC7BzB,EAAcA,EAAY0B,MAAM,GAAG,EAAE,CAAC,GAEtC1B,EAAYyB,QAAQ,GAAG,IAAM,KAC7BzB,EAAcA,EAAY0B,MAAM,GAAG,EAAE,CAAC,GAEnC1B,CACX,iDApDSH,EAAe,CAAA,iCAAfA,EAAe8B,QAAf9B,EAAe+B,UAAAC,WAFZ,MAAM,CAAA,CAAA,SAEThC,CAAe,GAAA", "names": ["DEFAULT_LANG", "LOCAL_STORAGE_LANG_KEY", "LanguageService", "constructor", "availableLang", "browserLang", "localStorage", "getItem", "getBrowserLang", "useLang", "match", "_langSource", "BehaviorSubject", "languageChange$", "asObservable", "pipe", "startWith", "shareReplay", "use", "lang", "setItem", "next", "currentLang", "getValue", "window", "navigator", "languages", "language", "browserLanguage", "userLanguage", "indexOf", "split", "factory", "\u0275fac", "providedIn"] }