File size: 601 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
import getCurrentLocaleSlug from 'calypso/state/selectors/get-current-locale-slug';
/**
* Get an Intl.Collator() for the current locale to enable localized sorting.
* @param {Object} state Redux state
* @returns {Object} Intl.Collator
*/
const getCurrentIntlCollator = ( state ) => {
const currentLocaleSlug = getCurrentLocaleSlug( state );
// Backup locale in case the user's locale isn't supported
const sortLocales = [ 'en' ];
if ( currentLocaleSlug ) {
sortLocales.unshift( currentLocaleSlug );
}
return new Intl.Collator( sortLocales );
};
export default getCurrentIntlCollator;
|