Created
December 13, 2021 15:21
-
-
Save FunnyGhost/6639365e43c33583678ba7ee03630a7b to your computer and use it in GitHub Desktop.
Browser Language Service
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Injectable } from '@angular/core'; | |
import { LanguageService, LanguageShortName } from 'somewhere'; | |
@Injectable() | |
export class WebLanguageService extends LanguageService { | |
constructor() { | |
super(); | |
} | |
getLanguage(defaultLanguage: LanguageShortName): LanguageShortName { | |
const deviceLanguage = window?.navigator.language?.substring( | |
0, | |
2 | |
) as LanguageShortName; | |
return this.SUPPORTED_LANGUAGES.includes(deviceLanguage) ? deviceLanguage : defaultLanguage; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment