|
Boost Users : |
From: Vladimir Prus (ghost_at_[hidden])
Date: 2008-02-19 11:32:56
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.
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.
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.
- Volodya
>
> Cheers,
> 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