Taligent's Message Formatting Demo Guide

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.

  1. 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.

  1. Pull down the Locale menu
  2. 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.

  1. 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.

  1. 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.

  1. Select the text "no files" in the pattern, and replace it by "not a single file"
  2. 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.

  1. 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.
  2. Select the value in the Argument 0 field and return the value to "0".
  3. 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.

  1. Select the U.S. English locale
  2. In the Pattern field change "1<" to "2#"
  3. Click in {0...}, just before the final brace.
  4. Type in " |10< many files"
  5. Enter a number larger than 10 for the value in the Argument 0 field
  6. 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.