简体   繁体   English

如何显示href的react-intl翻译结果?

[英]How to display react-intl translation result for href?

Is there any option to show contact number as <a class="footer__links--contact--phone" href="tel:+44 1234 1234 12"> in react-int ? 是否有任何选项可以在react-int <a class="footer__links--contact--phone" href="tel:+44 1234 1234 12">联系人号码显示为<a class="footer__links--contact--phone" href="tel:+44 1234 1234 12">

import React from 'react';
import { FormattedMessage } from 'react-intl';
import messages from './messages';
    const ContactList = () => (
      <div className="footer__links--contact">
        <pre>{JSON.stringify(messages.phone)}</pre>
        <a className="footer__links--contact--phone" href={`tel:${messages.phone}`}>
          <FormattedMessage {...messages.phone} />
          <p className="footer__opening-hours">
            <FormattedMessage {...messages.availability} />
          </p>
        </a>
      </div>
    );
    export default ContactList;

在此处输入图片说明

You can provide function as child component: 您可以提供功能作为子组件:

    <FormattedMessage {...messages.phone}>
       {phone => (
         <a className="footer__links--contact--phone" href={`tel:${phone}`}>
           {phone}
         </a>
       )}
     </FormattedMessage>

Does this line correctly display the telephone? 此线路是否正确显示电话?

<pre>{JSON.stringify(messages.phone)}</pre>

If so then I believe you also have to apply the same logic to the href tag because of how the template string is converting the object to a string. 如果是这样,那么我相信您还必须对href标签应用相同的逻辑,因为模板字符串是如何将对象转换为字符串的。

<a className="footer__links--contact--phone" href={`tel:${JSON.stringify(messages.phone)}`}>

Also be sure that you are using the correct format for the international prefix. 另外,请确保您使用的国际前缀格式正确。 The examples given in the w3 docs use dashes instead of spaces so that may be something to consider as well. w3文档中给出的示例使用破折号而不是空格,因此也可能需要考虑。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM