|
From: Doug F. <dou...@go...> - 2010-07-27 20:23:51
|
I'd like to propose an extension to the syntax understood by PluralFormat to
make it easier to deal with a larger class of messages that vary based on
number. For example:
format(1): "Wrote xxx.txt."
format(2): "Wrote xxx.txt and yyy.txt."
format(3): "Wrote xxx.txt, yyy.txt, and one other file."
format(7): "Wrote xxx.txt, yyy.txt, and 5 other files."
I'm proposing no API changes, this is only a syntax change. An English
pattern string for this example would look as follows (line breaks are for
clarity):
"offset:2
=1 {Wrote {FILE_1}.}
=2 {Wrote {FILE_1} and {FILE_2}.}
one {Wrote {FILE_1}, {FILE_2}, and one other file.}
other {Wrote {FILE_1}, {FILE_2}, and # other files.}"
There are two new optional syntax elements:
- the 'offset:' keyword ("offset:2" above)
- the explicit value selector ("=1" and "=2" above)
An explicit value selector consists of '=' immediately followed by an
decimal or integer number with no intervening space. This identifiues the
sub-pattern to use when the PluralFormat is asked to format a particular
value. In this example, '1' and '2' have explicit values, and so formatting
the values 1 and 2 will result in the sub-patterns preceded by these
selectors. When formatting, any explicit value selectors are tested first,
before the plural rules are used to generate a plural selector.
The 'offset:' keyword is followed by a (decimal or integer) number and then
a space. This offset is the amount to subtract from the passed-in value
before running the plural rules and performing number substitutions, but
after examining the explicit selectors. In this example, the offset value
is 2, so if the input value does not match an explicit selector, 2 is
subtracted from the input value before passing it to the plural rule and
performing any '#' replacements. When formatting the value 3, subtracting
the offset results in the value 1, which English plural rules convert to the
selector "one". When formatting the value 7, subtracting the offset results
in the value 5, which English plural rules convert to the selector "other",
and "#" in the result sub-pattern is replaced with "5" (the adjusted value)
before it is returned.
These extended pattern strings, when embedded in a message format, are more
compact and simpler to translate and call than, say, combining a choice
format with a plural format, and tweaking the calling code to provide the
non-adjusted value to the choice format and the adjusted value to the plural
format. Simplifying the calling code also makes it easier to share messages
among multiple implementations.
Please respond by August 9th.
Doug
|