WAS v8.5 > Develop applications > Develop Internationalization service > Tasks: Internationalizing interface strings (localizable-text API) > Compose language-specific strings > Set optional localization values

Compose complex strings

Perform this task to insert variable substrings into a localized string.

Identify strings that need to be localized.

The localized-text package supports the substitution of variable substrings into a localized string that is retrieved from the message catalog by key.

  1. In the message catalog, specify the location of the substitution in the string to be retrieved. Variable components are designated by braces (for example, {0}).
  2. In application code, create a LocalizableTextFormatter instance, passing in an array containing the variable value. If the variable substring must be localized, we can create a nested LocalizableTextFormatter instance and pass the instance in instead of a value.
  3. Generate a localized string.
    When a format method is called on a formatter instance, the formatter takes each element of the array passed in the previous step and substitutes it for the placeholder with the matching index in the string that is retrieved from the message catalog. For example, the value at index 0 in the array replaces the {0} variable in the retrieved string.


Example

The following line from an English message catalog shows a string with a single substitution:

The same key in message catalogs for other languages has a translation of this string with the variable at the appropriate location for each language.

The following code shows the creation of a single-element argument array and the creation and use of a LocalizableTextFormatter instance:

public void updateAccount(String transactionType) {
   ...
   Object[] arg = {new String(this.accountNumber)};
   ...
   LocalizableTextFormatter successLTF =
      new LocalizableTextFormatter ("BankingResources",
                                    "successfulTransaction",
                                    "BankingSample",
                                    arg);
   ...
   successLTF.format(this.applicationLocale);
   ...}


Subtopics


Related


Set optional localization values


Reference:

LocalizableTextFormatter class


+

Search Tips   |   Advanced Search