Boost logo

Boost :

From: Vladimir Prus (ghost_at_[hidden])
Date: 2002-12-17 05:20:42


Peter Dimov wrote:
>>I think that we also need to consider the problem of translating a
>>filesystem_error to a localized error message.
>
>
> In particular, consider this example of a what() string:
>
> File system error: move_file(): nonexistent, something_else: The system
> cannot find the file specified.
>
> generated by
>
> boost::filesystem::rename("nonexistent", "something_else");
>
> There is no way to localize it, as it (a) contains non-localizable dynamic
> path names embedded within the message,

Seems like there is quite a few alternatives:

1. Perform localization at the point where exception is thrown. The biggest
    problem there is getting the right message catalog.

    - I don't like standard message catalogs at all, because they require
      integer ids. And are they implemented anywhere, btw? It's possible
      to add gettext-like message catalog facet to locale, though.

    - What locale to use? Global? -- not sure. Locale passed to the
      function that throws --- uhmm... passing locale to every filesystem
      function is plain boring.

2. Keep the format string and variable arguments in exception class.
     This is similiar, but IMO, different from the idea to specify values
     of 'what'. E.g

     class filesystem_exception {
     public:
        const string& format_string() const;
         const vector<string>& parameters() const;

        const char* what() const {
                boost::format f(format_string());
                const vector<string>& p = parameters();

                for (size_t i = 0; i < p.size(); ++i)
                        f % p[i];

                // Do something tricky to return pointer
                // to f.str().c_str(), but prevent the
                // string from going out of scope.
         }

        void imbue(const locale&);
     };

     So, if you want to get localized "what", you'll imbue the appropriate
     locale. How does that look?

     Don't really know how to localize parameters themself...

> and (b) the "The system..." part
> obtained from FormatMessage may already have been localized by the OS.

I think that you should know if it's localized or not somehow, and make it
localized if possible. Otherwise, we're back to the problem of localizing
arguments.

- Volodya


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk