2017-06-20 67 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