react-code-dataset / wp-calypso /client /state /selectors /get-current-intl-collator.js
Devendra174's picture
Upload folder using huggingface_hub
1e92f2d verified
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;