Hi,

2013/5/4 Matthieu Monrocq <[email protected]>

>
> 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! ?
>>
>
> 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).
>

In fact, there is nothing preventing fully flexible logic in translations
if they are themselves written in Rust (penging some variadic trait mojo in
the macro that will invoke the translation):

pub static messages: &'static [Tr] = &[
        Tr("Simple text",
           &Text("Простой текст") as &Message),
        Tr("%d elements",
           &Fmt(|n: int| {
                match (ru::num_case(n)) {
                    ru::NumCaseNone => ~"ни одного элемента",
                    ru::NumCase1    => fmt!("%d элемент", n),
                    ru::NumCase2    => fmt!("%d элемента", n),
                    _               => fmt!("%d элементов", n)
                }
            }) as &Message)
    ];

Gettext is for C programmers B-)

-- 
  Mikhail
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to