2017-06-20 68 views
0

我已经知道如何通过react-native-i18n生成i18n字符串。例如,将属性添加到R​​eact Native中的i18n字符串

// en.js source 
{ 
    "hello": "Hello, {{name}}." 
} 

// use 
I18n.t("hello", { name: "John" }) 

,它显示Hello, John.

我也知道如何生成属性串:

<Text> 
    This is a <Text style={{fontWeight: 'bold'}}>bold<Text> word. 
<Text> 

,它显示This is aboldword

问题是,我如何添加属性到一个国际化的模板字符串?任何这个库?

// en.js source 
{ 
    "hello": "Hello, <b>{{guest}}</b>. I'm {{host}}." 
} 

// use 
I18n.t("hello", { guest: "John", host: "Sam" }) 
  • 预计:Hello,John. I'm Sam.
  • 什么我:Hello, <b>John</b>. I'm Sam.

回答

1

可以使用反应 - i18next它支持的反应将其翻译组件内部组件:

<div>{t('simpleContent')}</div> 
<Trans i18nKey="userMessagesUnread" count={count}> 
    Hello <strong title={t('nameTitle')}>{{name}}</strong>, you have {{count}} unread message. <Link to="/msgs">Go to messages</Link>. 
</Trans> 

以及更多...了解更多http://react.i18next.com