@@ -343,18 +343,27 @@ function getStore(config, router) {
343343
344344 acceptedLanguages : state => {
345345 const languages = { } ;
346- // Implement in ascending order:
347- languages [ 'en' ] = 0.1 ;
348- if ( Array . isArray ( state . supportedLocales ) ) {
349- state . supportedLocales . forEach ( locale => languages [ locale ] = 0.2 ) ;
350- }
346+ // Implement in ascending order so that the higher priority entries override previous ones
347+ // Wildcard has the lowest priority
348+ languages [ '*' ] = 0.1 ;
349+ // The fallback locale for STAC Browser
351350 if ( Utils . hasText ( state . fallbackLocale ) ) {
352- languages [ state . fallbackLocale ] = 0.5 ;
351+ languages [ state . fallbackLocale ] = 0.2 ;
353352 }
353+ // Locales defined by the browser in ascending order
354+ // For example, if the browser has "de-CH,de,en" configured,
355+ // the priority would be: de-CH (0.8), de (0.7), en (0.6)
356+ // The priority never goes below 0.3
354357 if ( Array . isArray ( navigator . languages ) ) {
355- navigator . languages . forEach ( locale => languages [ locale ] = 0.7 ) ;
358+ navigator . languages . forEach ( ( locale , i ) => languages [ locale ] = 0.8 - Math . min ( ( i * 0.1 ) , 0.5 ) ) ;
356359 }
357360 if ( Utils . hasText ( state . locale ) ) {
361+ // Add the more generic locale code as well.
362+ // For example, 'de' in addition to 'de-CH'.
363+ if ( state . locale . includes ( '-' ) ) {
364+ languages [ state . locale . substring ( 0 , 2 ) ] = 0.9 ;
365+ }
366+ // The currently selected locale has the highest priority
358367 languages [ state . locale ] = 1 ;
359368 }
360369 return Object . entries ( languages )
@@ -367,7 +376,7 @@ function getStore(config, router) {
367376 }
368377 return 0 ;
369378 } )
370- . map ( ( [ l , q ] ) => q >= 1 ? l : `${ l } ;q=${ q } ` )
379+ . map ( ( [ l , q ] ) => q >= 1 ? l : `${ l } ;q=${ q . toFixed ( 1 ) } ` )
371380 . join ( ',' ) ;
372381 }
373382 } ,
0 commit comments