import { locales , locale } from './core' ; import { get } from 'svelte/store' ; interface IENavigatorLanguage { userLanguage ? : string ; } export const getBrowserLocale = ( defaultLocale = 'en' ) => { const targets = typeof window === 'undefined' ? [ defaultLocale ] : window . navigator . languages || [ ( window . navigator as IENavigatorLanguage ) . userLanguage || window . navigator . language , ] ; const currentLocales = get ( locales ) ; for ( let i = 0 ; i < targets . length ; i = i + 1 ) { if ( currentLocales . includes ( targets [ i ] ) ) return targets [ i ] ; const bestMatch = currentLocales . find ( ( locale ) => targets [ i ] . startsWith ( locale ) ) ; if ( bestMatch ) return bestMatch ; } const currentLocale = get ( locale ) ; return currentLocale || currentLocales [ 0 ] ; } ;