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
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.
The News’ banner notification includes a phrase indicating the number of new stories, as shown in Figure 11-4.
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}
.
3.16.203.65