Skip to content

Commit

Permalink
fi: UniversalLink render in Slate RichTextWidget
Browse files Browse the repository at this point in the history
  • Loading branch information
giuliaghisini committed Oct 24, 2023
1 parent 14b28ce commit 9cb2ca5
Showing 1 changed file with 25 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import React from 'react';
import PropTypes from 'prop-types';
import { useIntl } from 'react-intl';
import { useIntl, defineMessages } from 'react-intl';
import { HashLink as Link } from 'react-router-hash-link';
import { useSelector } from 'react-redux';
import {
Expand All @@ -21,7 +21,12 @@ import { matchPath } from 'react-router';
import { Icon } from 'design-comuni-plone-theme/components/ItaliaTheme';

import config from '@plone/volto/registry';

const messages = defineMessages({
opensInNewTab: {
id: 'opensInNewTab',
defaultMessage: 'Apre in un nuovo tab',
},
});
const UniversalLink = ({
href,
item = null,
Expand All @@ -33,7 +38,20 @@ const UniversalLink = ({
overrideMarkSpecialLinks = false,
...props
}) => {
const intl = useIntl();
let translations = {
opensInNewTab: {
defaultMessage: messages.opensInNewTab.defaultMessage,
},
};
//questo perchè il provider di intl non è sempre definito, ad esempio in slate_wysiwyg_box (Slate RichTextWidget)
try {
const intl = useIntl();
Object.keys(translations).forEach(
(k) => (translations[k].message = intl.formatMessage(messages[k])),
);
} catch (e) {
console.log('Cannot use intl here. View default messages.', e);
}
const token = useSelector((state) => state.userSession?.token);

let url = href;
Expand Down Expand Up @@ -102,9 +120,10 @@ const UniversalLink = ({
tag = (
<a
href={url}
title={`${title ? title + ' - ' : ''}${intl.formatMessage({
id: 'opensInNewTab',
})}`}
title={`${title ? title + ' - ' : ''}${
translations.opensInNewTab.message ??
translations.opensInNewTab.defaultMessage
}`}
target={
!checkedURL.isMail &&
!checkedURL.isTelephone &&
Expand Down

0 comments on commit 9cb2ca5

Please sign in to comment.