import I18n from 'i18n-js' ; const currentLocale = getLanguageFromBrowser ( ) || I18n . currentLocale ( ) ; I18n . locale = currentLocale ; export default I18n ; returns { string | undefined } function getLanguageFromBrowser ( ) { if ( navigator && typeof navigator === 'object' ) { const { language , browserLanguage , userLanguage } = navigator as Navigator & { userLanguage ? : string ; browserLanguage ? : string ; } ; return language || browserLanguage || userLanguage ; } return undefined ; }