summaryrefslogtreecommitdiffstats
path: root/src/pybind/mgr/dashboard/frontend/src/app/shared/services/language.service.ts
blob: d2705ee36044249c0e9e1a3266bbe3c60790e86f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import { HttpClient } from '@angular/common/http';
import { Inject, Injectable, LOCALE_ID } from '@angular/core';

import { environment } from '~/environments/environment';

@Injectable({
  providedIn: 'root'
})
export class LanguageService {
  constructor(private http: HttpClient, @Inject(LOCALE_ID) protected localeId: string) {}

  getLocale(): string {
    return this.localeId || environment.default_lang;
  }

  setLocale(lang: string) {
    document.cookie = `cd-lang=${lang}`;
  }

  getLanguages() {
    return this.http.get<string[]>('ui-api/langs');
  }
}