Internationalization

The Mojo framework includes Mojo.Format, a set of locale-aware methods to assist you with formatting different types of text strings. The available methods are summarized in Table 11-2.

Table 11-2. Mojo.Locale and Mojo.Format methods

Method

Description

Mojo.Locale.getCurrentLocale()

Returns the currently set locale as an ISO 639-formatted string (e.g., en_us for US English)

Mojo.Locale.getCurrentFormatRegion()

Returns the currently set region as an ISO 639-formatted string (e.g., us for US English)

Mojo.Format.formatDate()

Formats the date object appropriately for the current locale

Mojo.Format.formatRelativeDate()

Formats the date object as with formatDate(), but returns yesterday/today/tomorrow if appropriate, or the day of the week if in the last week

Mojo.Format.formatNumber()

Converts a number to a string using the proper locale-based format for numbers and number separators

Mojo.Format.formatCurrency()

Converts a number representing an amount of currency to a string using the proper locale-based format for currency; does not do any currency rate conversion, just formatting

Mojo.Format.formatChoice()

Formats a choice list to handle things like replacement parameters with plurals

Mojo.Format.formatPercent()

Converts a number to a percent string using the proper locale-based format for percentages

Mojo.Format.using12HrTime()

Returns true if the current locale uses 12-hour time or false if 24-hour time

Mojo.Format.getCurrentTimeZone()

Returns current timezone

The behavior of some of the widgets should be influenced by the selected locale. Currently, the Time Picker widget will hide the AM/PM panel if the current locale defaults to a 24-hour time format. There will be further integration of locale-specific behavior over time; check the Palm Developer site for updates in this area.

Back to the News: Multilingual Formatting

The News’ banner notification includes a phrase indicating the number of new stories, as shown in Figure 11-4.

News banner notification

Figure 11-4. News banner notification

But this isn’t linguistically correct (that is, 1 new item will display as “1 New Items”), nor will it localize properly. What’s needed is a way of expressing this in a conditional way that accounts for language differences. Mojo.Format.formatChoice() can address this need:

var bannerParams = {
    messageText: Mojo.Format.formatChoice(
        this.list[this.feedIndex].newStoryCount,
        $L("0##{title} : No New Items|1##{title} : 1 New Item|1>##{title} : 
          #{count} New Items"),
        {title: this.list[this.feedIndex].title, count: 
          this.list[this.feedIndex].newStoryCount}
    )
};

appController.showBanner(bannerParams, {action: "notification", 
index: this.feedIndex},
  this.list[this.feedIndex].url);

The call to formatChoice() passes an integer representing the quantity, as well as a set of choices. In this case, the choices are:

  • For a quantity of 0 then a string of No New Items

  • For a quantity of 1, then a string of 1 New Item

  • For a quantity greater than 1, then a string of #{count} New Items

The final argument includes the object that supplies the values to be substituted for the templates #{title} and #{count}.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.16.203.65