messageformat 

Send to Kindle
home » snippets » i18n » messageformat



Patterns and Their Interpretation

Ref: icu-project.org/…/MessageFormat.html, Pattern_Syntax

MessageFormat uses patterns of the following form:

message = messageText (argument messageText)*
argument = noneArg | simpleArg | pluralArg | selectArg | selectordinalArg

noneArg          =  '{'  argNameOrNumber  '}'
simpleArg        =  '{'  argNameOrNumber  ','  argType            [',' argStyle]  '}'
pluralArg        =  '{'  argNameOrNumber  ','  "plural"        ','   pluralStyle  '}'
selectArg        =  '{'  argNameOrNumber  ','  "select"        ','   selectStyle  '}'
selectordinalArg =  '{'  argNameOrNumber  ','  "selectordinal" ','   pluralStyle  '}'

argNameOrNumber  =  argName | argNumber
argName          =  [^[[:Pattern_Syntax:][:Pattern_White_Space:]]]+
argNumber        =  '0' | ('1'..'9' ('0'..'9')*)

argType          =  "number" | "date" | "time" | "spellout" | "ordinal" | "duration"
argStyle         =  "short" | "medium" | "long" | "full" | "integer" | "currency" | "percent" | argStyleText

pluralStyle      =  [offsetValue] ( explicitValue|pluralKeyword '{' message '}')+  // the "other" pluralKeyword is required.
offsetValue      =  "offset:" number
explicitValue    =  '=' number  // adjacent, no white space in between
pluralKeyword    =  'zero' | 'one' | 'two' | 'few' | 'many' | 'other' | keyword

selectStyle      =  (selectKeyword '{' message '}')+  // the "other" selectKeyword is required.
selectKeyword    =  'other' | keyword

keyword          =  [^[[:Pattern_Syntax:][:Pattern_White_Space:]]]+

Pattern_White_Space between syntax elements is ignored, except:


Plurals

Predefined keyword's:  'zero', 'one', 'two', 'few', 'many' and 'other'.

You must always define message text for the other case (it's the fallback.)

Matching Priority / Algorithm

Formatting


Gender and "select"

The main use case for the select format (selectArg) is gender based inflection.

When names or nouns are inserted into sentences, their gender can affect pronouns, verb forms, articles, and adjectives. Special care needs to be taken for the case where the gender cannot be determined. The impact varies between languages:

The fallback keyword is "other" (just like with pluralization.)  Some common keywords are: "male", "female", "mixed" (for groups of people) and "Unknown".


Quoting

Recommendation: Use the real apostrophe character, «» (U+2019), for human-readable text, and use the ASCII apostrophe, «'» (U+0027), only in program syntax, like quoting in MessageFormat. See the annotations for U+0027 Apostrophe in The Unicode Standard.