如何在react intl中添加格式化消息的链接?

you*_*ter 2 reactjs react-intl

我正在使用 react intl ^2.4.0 版本。我想在已翻译的格式化消息中添加链接。我将它与react cookie 法结合使用

我尝试使用类似的东西:

const link = <a href="google.com">log in</a>;
const msg = `this website uses cookies ${link}`
Run Code Online (Sandbox Code Playgroud)

但没有运气。

const cookieMsg = (
    <FormattedMessage
        id="text"
        defaultMessage="This website uses cookies LINK HERE."
    />
);
Run Code Online (Sandbox Code Playgroud)

在 CookieBanner 中:

<IntlProvider locale={lang} messages={messages[lang]}>
    <>
        <CookieBanner
            message={msg}
            ...
        />
    </>
</IntlProvider>

Run Code Online (Sandbox Code Playgroud)

我直接在 app.js 中渲染。这里是:

<CookieBanner
     message={cookieMsg}
     acceptButtonText={cookieBtn}
     privacyPolicyLinkText={cookiePrivacy}
     policyLink="https://www.google.com"
     showMarketingOption={false}
     showStatisticsOption={false}
     showPreferencesOption={false}
     styles={{
              optionWrapper: {
                  display: "none"
               }
            }}
     />
Run Code Online (Sandbox Code Playgroud)

Ami*_*han 6

您可以将链接作为值传递给 FormattedMessage

const cookieMsg = (
    <FormattedMessage
        id="text"
        defaultMessage="This website uses cookies {link}."
        values={{
            link: <a href="google.com">
                <FormattedMessage
                    id="link"
                    defaultMessage="log in"
                />
            </a>
        }}
    />
);
Run Code Online (Sandbox Code Playgroud)