Message formats are used to put together sequences of strings, numbers, dates, and other formats to create messages. The message formatters facilitate localization because they prevent both hard-coding of message strings, and hard-coding of the concatenation sequence for portions of message strings. This means localizers can change the content, format, and order of any text as appropriate for any language.About the Message Format Formatting Arguments
Supporting Multiple Choices
About the Message Format
The pattern is a sequence of text and arguments, all of which can be edited. The positions of the arguments within the sequence are indicated by a pair of braces "{...}" containing a digit n identifying the argument. The pattern in the demo applet has three arguments, numbered 0, 1, and 2. The arguments can appear in any order within the sequence, which can be edited and modified.
To See This...
Do This...
You can move arguments freely within the sequence or delete arguments. You can also edit or translate any of the unformatted text.
- Move the string "on {2,date}" from the end of the pattern to the front and correct the capitalization
Translations are provided in the demo applet for several countries.
- Pull down the Locale menu
- Try several different locales with the up and down arrow keys (on Windows) or the mouse button (on Macintosh)
Note: To add a real '{' character to the pattern, use single quotation marks.
Formatting Arguments
The arguments can be either simple text strings or formattable, localizable objects. The pattern in the demo applet, for example, includes a date, an unformatted string, and a more complex format called a choice format (described below). You can edit these arguments at will. When localizing, you can also select any format to be associated with an argument.
To See This...
Do This...
You can modify the value of any argument.
- Select the "3" in the Argument 2 field and change it to another number--the formatted date adjusts to the new value
You can change the format of any argument.
- In the Pattern field change {2,date} to {2,date,yy.MMM.dd}
Supporting Multiple Choices
Choice formats, like that used for argument 0, let localizers create more natural messages, avoiding phrases like "3 file(s)". As shown here, the correct text can be chosen for different numbers. This works even in more complicated contexts, such as Slavic languages which have more than one plural format based on the number involved. A particular choice is chosen based on the value of the argument, and each choice can be edited individually.
Look also at the format for the choice associated with values of 2 and higher. Such choices allow for a degree of flexibility in using different formats.
To See This...
Do This...
You can edit the value of any of the choice options.
- Select the text "no files" in the pattern, and replace it by "not a single file"
- Select the value in the Argument 0 field and type in "0"
You can establish different choices for parameters based on the value of an argument, so that strings are substituted that agree numerically.
- Select the value in the Argument 0 field and type in "0", then replace it with a "1", and then with a "2". The string changes correspondingly.
- Select the value in the Argument 0 field and return the value to "0".
- Choose the French or German locale and notice that it makes correct substitutions in any language.
You can add as many alternatives as you need for different value ranges.
- Select the U.S. English locale
- In the Pattern field change "1<" to "2#"
- Click in {0...}, just before the final brace.
- Type in " |10< many files"
- Enter a number larger than 10 for the value in the Argument 0 field
- The string "many files" is substituted in the resulting message
You can type in other text in the pattern, arguments, or choices fields to see different formatting behaviors. Try it out!
The source.
This page incorporates material or code copyrighted by Taligent, Inc. For more information on international resources, see their International Fact Sheet.