Boost logo

Boost Users :

From: Filip Konvička (filip.konvicka_at_[hidden])
Date: 2008-02-20 22:02:23


Vladimir Prus 19.2.2008 17:32:
> Filip Konvička wrote:
>
>
>>>> Moreover, some english strings seem to be hard-coded in program_options
>>>> (exception messages, etc.) There should be another way of handling
>>>> cmdline errors - we can't presume that the user understands english
>>>> text. And there does not seem to be a way of translating the po
>>>> exceptions to localized strings without accessing/changing some po
>>>> internals.
>>>>
>>>>
>>> I suspect all boost libraries share this problem, and nobody came with
>>> a nice solution for solving this.
>>>
>>> I can surely provide a hook, specific for program_options, that is called
>>> to translate messages.
>>>
>>>
>> Sure, but program_options is in fact implementation of some UI so the
>> need for user interaction is higher than with some other libraries.
>>
>> I think that providing some additional data members in the exception
>> classes would be sufficient. That way, you don't need to provide any
>> hooks at all.
>>
>> The current pattern for using exceptions is something like
>>
>> throw my_exception("some text "+param+": some other text "+param2);
>>
>> (sometimes the string construction is in my_exception's constructor).
>>
>> I'd rather see
>>
>> throw my_exception(param, param2);
>>
>> and somewhere in my_exception:
>>
>> class my_exception {
>> ....
>> public:
>> string param;
>> string param2;
>>
>> string what() const {
>> return "some text "+param+": some other text "+param2;
>> }
>> }
>>
>
> Then, if you want to provide a localized message, you should actually
> write code to construct a message.
>
Yes. According to my example, I could do (but I don't have to if I don't
want, that's the point)

try {
   // work with PO
}
catch(my_exception& e) {
   cout << "My localized message for my_exception with p1=" << e.param
<< " p2=" << e.param2 << endl;
}
// ...
// possibly catch/translate other PO exceptions
// ...
catch(some_basic_po_exception& fallback) {
  cout << fallback.what() << endl; // use default string
}
> If there's a localization hook, you'll basically have to run a tool
> to extract the string to be localized (program_options.po can be
> shipped for those who use gettext), translate it, and install it.
>
Uh, I'd never suggest such thing :-)
> Of course, it might not work on Windows -- but I'm not exactly sure
> how localization works on windows, in practice. Numeric message
> ids look like nightmare to maintain.
>
Agreed.

Filip


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net