Skip to content

Instantly share code, notes, and snippets.

@FunnyGhost
Created December 13, 2021 15:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FunnyGhost/6639365e43c33583678ba7ee03630a7b to your computer and use it in GitHub Desktop.
Save FunnyGhost/6639365e43c33583678ba7ee03630a7b to your computer and use it in GitHub Desktop.
Browser Language Service
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