> Hi,
>
> 2013/5/3 Graydon Hoare <[email protected]>
>
> > (Erm, it might also be worthwhile to consider message catalogues and
> > locale-facets at this point; the two are closely related. We do not have a
> > library page on that topic yet, but ought to. Or include it in the lib-fmt
> > page.)
>
> If you are talking about gettext-like functionality, usually this and
> format strings are thought of as independent processing layers: format
> strings are translated as such and then fed to the formatting function.
> This brings some ramifications, as the order of parameters in the
> translated template can change, so the format syntax has to support
> positional parameters. But this also allows to account for data-derived
> context such as numeral cases, without complicating the printf-like
> functions too much.
> There are other difficulties with localizing formatted messages that are
> never systematically solved, for example, accounting for gender. In all, it
> looks like an interesting area for library research, beyond the basic
> "stick this value pretty-printed into a string" problem.
>
> Cheers,
> Mikhail
Gettext is indeed dependent on the fact that the format syntax allows
positional parameters.
I'd like to point out that gettext also makes use of a "feature" of the
formatting function. Namely, the fact that it is not an error to call this
function with more arguments than what the format string expects.
In C, printf("%d", 1, 2) outputs "1". In Rust, fmt!("%d", 1, 2) is a
compilation error.
The use case for using this feature is briefly explained here
http://www.gnu.org/software/gettext/manual/gettext.html#Plural-forms
A simple example is that, given the string "there are %d frogs", the translator
may want to translate it to "il n'y a aucune grenouille" instead of "il y a 0
grenouilles". In this case, the resulting function call would be printf("il n'y
a aucune grenouille", 0), which is valid since the unused argument will be
ignored.
By the way, it occurs to me that fmt! requires a string literal as its first
argument. How could a system like gettext, whose role is to substitute the
format string at runtime, could work with fmt! ?
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev