import { Injectable } from '@angular/core' ; import { TranslateService } from '@ngx-translate/core' ; import { Locale } from '../storage/Locale' ; export enum Language { EN = 'en' , ES = 'es' , FR = 'fr' , AR = 'ar' , RU = 'ru' , UA = 'ua' } @ Injectable ( ) export class LocaleService { private readonly localStorage = new Locale ( ) ; /**
     *
     */ constructor ( private translate ) { this . initLanguage ( ) ; } public switchLanguage ( lang ) { this . translate . use ( lang ) ; this . localStorage . set ( lang ) ; } private initLanguage ( ) { this . translate . setDefaultLang ( Language . EN ) ; const navigatorLang = navigator . language . length > 2 ? navigator . language . slice ( 0 , 2 ) : navigator . language ; this . switchLanguage ( ( this . localStorage . get ( ) as Language ) || ( navigatorLang as Language ) ) ; } }