forked from teuchezh/dynamic-weather-card
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathresolveLanguage.ts
More file actions
26 lines (22 loc) · 905 Bytes
/
Copy pathresolveLanguage.ts
File metadata and controls
26 lines (22 loc) · 905 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import type { SupportedLanguage } from './types';
interface ResolveLanguageOptions {
configLang?: string;
hassLang?: string;
}
export const resolveLanguage = ({ configLang, hassLang }: ResolveLanguageOptions = {}): SupportedLanguage => {
if (configLang && configLang !== 'auto') return configLang as SupportedLanguage;
if (hassLang) return hassLang as SupportedLanguage;
// Only outside Home Assistant
if (typeof navigator !== 'undefined' && navigator.language) {
const lang = navigator.language.toLowerCase();
if (lang.startsWith('ru')) return 'ru';
if (lang.startsWith('de')) return 'de';
if (lang.startsWith('nl')) return 'nl';
if (lang.startsWith('fr')) return 'fr';
if (lang.startsWith('it')) return 'it';
if (lang.startsWith('es')) return 'es';
if (lang.startsWith('sk')) return 'sk';
if (lang.startsWith('hu')) return 'hu';
}
return 'en';
};