最近、私は複数ページリートアプリケーションで国際化のために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
ステップ。このとき
args
は
cacheId
は
"["预览","zh_CN",[]]"
あると
format
は
undefined
カスタムロケールデータを追加する方法はありで、["预览", "zh_CN", Object]
で正しく
:
messages={zh_CN}
は、次のようなあなたの翻訳を含むキーバリューストアでなければなりません。最終ページに翻訳された言葉が得られます。しかし、あまりにもエラーを取得します。だから、私は何が起こったのか分かりません。 –'addLocaleData'と' IntlProvider'に渡すべきオブジェクトと同じオブジェクトではないということだけです。 'IntlProvider'は、' addLocaleData'が異なるロケール設定のディクショナリを予期しているとき、すべての翻訳のリストを期待します。私はそれがなぜあなたのエラーを持っているのかわからない。 –