translation-message.tsx 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import { Trans, useTranslation } from 'react-i18next'
  2. import Close from './close'
  3. import usePersistedState from '../hooks/use-persisted-state'
  4. import getMeta from '../../utils/meta'
  5. import { SuggestedLanguage } from '../../../../types/system-message'
  6. function TranslationMessage() {
  7. const { t } = useTranslation()
  8. const [hidden, setHidden] = usePersistedState('hide-i18n-notification', false)
  9. const config = getMeta('ol-suggestedLanguage') as SuggestedLanguage
  10. const currentUrl = getMeta('ol-currentUrl') as string
  11. if (hidden) {
  12. return null
  13. }
  14. return (
  15. <li className="system-message">
  16. <Close onDismiss={() => setHidden(true)} />
  17. <div className="text-center">
  18. <a href={config.url + currentUrl}>
  19. <Trans
  20. i18nKey="click_here_to_view_sl_in_lng"
  21. components={[<strong />]} // eslint-disable-line react/jsx-key
  22. values={{ lngName: config.lngName }}
  23. shouldUnescape
  24. tOptions={{ interpolation: { escapeValue: true } }}
  25. />
  26. <img
  27. className="ms-1"
  28. src={config.imgUrl}
  29. alt={t('country_flag', { country: config.lngName })}
  30. aria-hidden
  31. />
  32. </a>
  33. </div>
  34. </li>
  35. )
  36. }
  37. export default TranslationMessage