import inflection from 'inflection' ; import { useStore } from 'react-redux' ; import { getResources } from '../reducer' ; import { useTranslate } from '../i18n' ; returns { GetResourceLabel } example export const useGetResourceLabel = ( ) : GetResourceLabel => { const store = useStore ( ) ; const translate = useTranslate ( ) ; return ( resource , count = 2 ) : string => { const resourceDefinition = getResources ( store . getState ( ) ) . find ( r => r ?. name === resource ) ; const label = translate ( `resources.${ resource }.name` , { smart_count : count , _ : resourceDefinition && resourceDefinition . options && resourceDefinition . options . label ? translate ( resourceDefinition . options . label , { smart_count : count , _ : resourceDefinition . options . label , } ) : inflection . humanize ( count > 1 ? inflection . pluralize ( resource ) : inflection . singularize ( resource ) ) , } ) ; return label ; } ; } ; export type GetResourceLabel = ( resource : string , count ? : number ) => string ;