On Sat, May 4, 2013 at 1:15 PM, Olivier Renaud <o.ren...@gmx.fr> wrote:

> > Hi,
> >
> > 2013/5/3 Graydon Hoare <gray...@mozilla.com>
> >
> > > (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
> Rust-dev@mozilla.org
> https://mail.mozilla.org/listinfo/rust-dev
>

Maybe we are taking this a bit backward ?

I understand that things like gettext, at the moment, only substitute the
"text"; but that may be seen as mistake rather than a feature.

Instead, we could perfectly imagine a "gettext-like" equivalent that takes
both an "original" format string (to be translated) *and* its arguments and
then will use fmt! under the hood to produce a fully translated string to
be fed to the Writer instance.

Note that anyway for a proper translation gettext requires access to
certain elements; for example for correct plural forms to be picked (esp in
Polish).

With this out of the way, not only are positional arguments not required
any longer, but we can also avoid ignoring a mismatch between the number of
arguments supplied (and their types) and those expected by the original
format-string. There is no point in being as loose as C.

-- Matthieu
_______________________________________________
Rust-dev mailing list
Rust-dev@mozilla.org
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to