2017-08-02 3 views
2

最近、私は複数ページリートアプリケーションで国際化のためにReact-Intlを使用しています。React-Intl:IntlMessageFormatに追加されたロケールデータに `pluralRuleFunction`がありません

"IntlProviderWithLocal"というコンポーネントを作成してカスタムロケールを追加します。

import React from 'react' 
import {IntlProvider, addLocaleData} from 'react-intl'; 

import zh_CN from '../../../components/i18n/zh_CN/angular_locale' 

export default (props) => { 
    const {children, ...last} = props    

    addLocaleData(zh_CN);  
    return (
     <IntlProvider {...last} messages={zh_CN} > 
      {children} 
     </IntlProvider> 
    ) 
} 

しかし、私はエラーを取得:

Error formatting message: "publish.card.preview" for locale: "zh_CN", using default message as fallback

私はreact-intl/lib/index.es.jsにブレークポイントを設定し、それがvar formatter = state.getMessageFormat(message, locale, formats)でthrowedエラーを示しています。

formatsは空の配列です。

return function() { 
    var args = Array.prototype.slice.call(arguments); 
    var cacheId = getCacheId(args); 
    var format = cacheId && cache[cacheId]; 

    if (!format) { 
     format = new (src$es5$$.bind.apply(FormatConstructor, [null].concat(args)))(); 

     if (cacheId) { 
      cache[cacheId] = format; 
     } 
    } 

    return format; 
}; 

最後に私がformat = new (src$es5$$.bind.apply(FormatConstructor, [null].concat(args)))();でエラーLocale data added to IntlMessageFormat is missing a pluralRuleFunction for :zh_CNを取得し、機能getMessageFormatステップ。このとき

argscacheId"["预览","zh_CN",[]]"あると formatundefined

カスタムロケールデータを追加する方法はありで、["预览", "zh_CN", Object]で正しく

答えて

1

あなたは、プロバイダへのあなたの翻訳を合格していないようです。私はzh_CNにはJSONであると確信している

messages = { 
    "publish.card.preview": "Preview" 
} 
return <IntlProvider {...last} messages={messages} > 
    ... 
</IntlProvider> 
+0

messages={zh_CN}は、次のようなあなたの翻訳を含むキーバリューストアでなければなりません。最終ページに翻訳された言葉が得られます。しかし、あまりにもエラーを取得します。だから、私は何が起こったのか分かりません。 –

+0

'addLocaleData'と' IntlProvider'に渡すべきオブジェクトと同じオブジェクトではないということだけです。 'IntlProvider'は、' addLocaleData'が異なるロケール設定のディクショナリを予期しているとき、すべての翻訳のリストを期待します。私はそれがなぜあなたのエラーを持っているのかわからない。 –

関連する問題