Boost logo

Boost :

Subject: Re: [boost] [locale] Review. Internationalization library?
From: Vicente BOTET (vicente.botet_at_[hidden])
Date: 2011-04-16 03:12:36


> Message du 16/04/11 08:04
> De : "Vicente BOTET"
> A : boost_at_[hidden]
> Copie à :
> Objet : [boost] [locale] Review. Internationalization library?
>
> Hi,
>
> from the name of the library Boost.Locale and the section "What is Boost.Locale?" I didn't get enough information about the motivation and the scope of the library. I think that maybe be this is due to the fact that the dependency to ICU hides a lot of features the library provides. I think that a direct link to what ICU is is a must, but I would expect a little bit more than "On the other hand, there is a great, well debugged, high quality, widely used ICU library that gives all of the goodies" in this section.
>
> >From my side if the library was named Boost.Internationalization I'm sure I would had take a look long time ago. Do you think that this renaming (or a shorter one) will cover the whole library or there are parts of the library that don't fall in the internationalization domain?
>
> As the review period has been extended, I will try to review at least the documentation.

I have made a diagonal reading and I find your library really interesting. I think I will spent quite more time reviewing it.

I have just a first minimal and formal remark. When I see the overloading of the translate function

message boost::locale::translate (char const *msg)
message boost::locale::translate (char const *context, char const *msg)
message boost::locale::translate (char const *single, char const *plural, int n)
message boost::locale::translate (char const *context, char const *single, char const *plural, int n)
message boost::locale::translate (std::string const &msg)
message boost::locale::translate (std::string const &context, std::string const &msg)
message boost::locale::translate (std::string const &context, std::string const &single, std::string const &plural, int n)
message boost::locale::translate (std::string const &single, std::string const &plural, int n)

this let me think that it would be difficult to know know what is the message, the context, the domain, whether the message is the singular or plural form.

The equivalent for (w)gettext uses the c-like idiom, i.e. uses different names.

std::string boost::locale::gettext (char const *id, std::locale const &loc=std::locale())
std::string boost::locale::ngettext (char const *s, char const *p, int n, std::locale const &loc=std::locale())
std::string boost::locale::dgettext (char const *domain, char const *id, std::locale const &loc=std::locale())
std::string boost::locale::dngettext (char const *domain, char const *s, char const *p, int n, std::locale const &loc=std::locale())
std::string boost::locale::pgettext (char const *context, char const *id, std::locale const &loc=std::locale())
std::string boost::locale::npgettext (char const *context, char const *s, char const *p, int n, std::locale const &loc=std::locale())
std::string boost::locale::dpgettext (char const *domain, char const *context, char const *id, std::locale const &loc=std::locale())
std::string boost::locale::dnpgettext (char const *domain, char const *context, char const *s, char const *p, int n, std::locale const &loc=std::locale())

Neither is satisfying me. I was wondering if the use of Boost.Parameters could help.

An alternative could also be to define some thin wrappers that state clearly what is the meaning of the string or const char * parameters, for example we could have

struct domain {
domain(const char*);
domain(std::string const&);
operator const char*() const;
operator std::string() const;
};

The same for context, plural. Note that we don't need to wrap the message itself as this parameter is mandatory.

The examples

cout << format(translate("You have 1 file in the directory",
"You have {1} files in the directory",files)) % files << endl;

button->setLabel(translate("File","open"));

could be written as

cout << format(translate("You have 1 file in the directory",
plural("You have {1} files in the directory"),files)) % files << endl;

button->setLabel(translate(context("File"),"open"));

With this modification, the (w)gettext could all share the same names and there will be no need to use c-like names.

What you think?

Best,
Vicente


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