Boost logo

Boost :

Subject: Re: [boost] [Locale] Preview of 3rd version
From: Artyom (artyomtnk_at_[hidden])
Date: 2010-09-13 05:49:21


> > When you translate a message it is uniquely defined by 4 parameters:
> >
> > - locale (for example "ru_RU")
> > - domain (for example "excel")
> > - context(for example "File Menu")
> > - id(for example "Open...")
> >
> > So:
> >
> > cout << translate("File Menu","Open...")
> > << translate("Internet Connection","Open...")
> > << translate("Open...")
> > << translate("File Menu","Close")
> > << translate("Internet Connection","Close")
> > << translate("Close")
> >
> > Require 6 different entries in the dictionary
> >
>
> In this example you're only using context parameters (where there is two
> parametters) right?

Locale is defined by imbuing it to the stream. i.e.

std::cout.imbue(my_generator("ru_RU.UTF-8"));

Now default domain is used, if you want to switch domain you use:

  cout << as::domain("excel") << translate("File Menu","Open...")

And the string would be taken from, for example
/usr/share/locale/ru_RU/LC_MESSAGES/foo.mo

dictionary (of course if the dictionary for foo was loaded before when you
defined domains)

Of course you can specify all 4 parameters as:

    std::locale ru_RU_locale = my_generator("ru_RU.UTF-8");

    std::string = translate("File
Menu","Open...").str<char>(ru_RU_locale,"excel");

Or little bit simpler in gettext style:

    std::string translated_open = dpgettext("excel","File
Menu","Open...",ru_RU_locale);

But... Usually you don't want to :-)

Artyom

      


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