ICUメッセージ構文リファレンス

すべての引数型、スタイル、エスケープシーケンス、ネストルールを網羅したICU MessageFormat構文の完全リファレンスカード。i18n開発者必携のクイックリファレンス。

Fundamentals

詳細な説明

ICU MessageFormat構文リファレンス

FormatJS、react-intl、vue-i18n、Angular i18nなどの国際化ライブラリで使用されるICU MessageFormat構文の包括的なクイックリファレンスです。

文法概要

message     = (text | argument)*
argument    = '{' argName (',' argType (',' argStyle)?)? '}'
argName     = identifier
argType     = 'number' | 'date' | 'time' | 'plural' | 'select' | 'selectordinal'
argStyle    = styleKeyword | pattern

シンプルな引数

パターン 入力 出力
Hello, {name} name="World" Hello, World
{a} + {b} = {c} a=1, b=2, c=3 1 + 2 = 3

数値フォーマット

パターン 入力 (en-US) 出力
{n, number} 1234.5 1,234.5
{n, number, integer} 1234.5 1,235
{n, number, currency} 42.5 $42.50
{n, number, percent} 0.25 25%

日付フォーマット

パターン スタイル 例 (en-US)
{d, date, short} short 1/15/24
{d, date, medium} medium Jan 15, 2024
{d, date, long} long January 15, 2024
{d, date, full} full Monday, January 15, 2024

複数形 (Plural)

{count, plural,
    =0 {No items}
    one {# item}
    other {# items}
}

複数形カテゴリ: zero, one, two, few, many, other

選択 (Select)

{gender, select,
    male {He}
    female {She}
    other {They}
}

序数選択 (Selectordinal)

{pos, selectordinal,
    one {#st}
    two {#nd}
    few {#rd}
    other {#th}
}

エスケープシーケンス

シーケンス 出力
'' リテラルシングルクォート '
'{' リテラル左波括弧 {
'}' リテラル右波括弧 }
'any text' クォート間のテキストは解析されない

ネストルール

plural、select、selectordinalのケース内に引数をネストできます:

{gender, select,
    male {He bought {count, plural, one {# item} other {# items}}}
    other {They bought {count, plural, one {# item} other {# items}}}
}

ネストの深さに制限はありませんが、深いネストはメッセージの翻訳を困難にします。可能な限り2レベルまでに抑えてください。

ユースケース

翻訳ファイルの作成やレビュー中にICU MessageFormat構文の完全なリファレンスが必要なi18nエンジニアと翻訳者。

試してみる — ICU Message Format Tester

フルツールを開く