Boost logo

Boost :

Subject: Re: [boost] [locale] Formal review of Boost.Locale library starts tomorrow
From: Artyom (artyomtnk_at_[hidden])
Date: 2011-04-17 11:39:55


----- Original Message ----
> From: Fabio Fracassi <f.fracassi_at_[hidden]>
> To: boost_at_[hidden]
> Sent: Sun, April 17, 2011 6:00:17 PM
> Subject: Re: [boost] [locale] Formal review of Boost.Locale library starts
>tomorrow
>
> On 16/4/2011 15:29, Artyom wrote:
>
> >> So I do not expect you to write such a thing, but if someone did I'd
> >> expect you to integrate it. By the way, can you "guesstimate" how much
> >> work it would take?
> >>
> >
> > I have no idea, for example to handle XLIFF format
> > it is required to have... an XML parser so I don't know
> > what would it take.
> >
>
> I understand that it is hard, so let me ask another question, if the
> gettext loading support was missing, how much time would someone need to
> implement it. Ballpark figure is enough (a day, a week, a month?).
>

It took me quite a long time due to fact that I needed
to implement C equation parsing (took a few days)
and to learn this format.

At the beginning I was using some MIT code but then I
had rewritten everything from the scratch.

So it took maybe about a week or so.

> >> Your docs do not say what happens when I do this:
> >> locale::format("Today is {1}.") % date(d)
> >> I'd expect it to work and give the date in some sensible default
>formatting.
>
> Can you answer the question above?
>

Actually, one of the conclusions from the review that it
is better for boost::locale::Date_time to have default
output as date time formatting not as a number so

boost::locale::date_time dt = ..;

boost::locale::format("Today is {1}") % dt would
display both date and time.

And if dt is boost::date_time::date object it would display
date as it was written to stream.

If you want to display only date or time you would have
to put:

   boost::locale::format("Today is {1,date}") % dt

As boost::locale does not have separate date and time class
but date_time - which combines both concepts of calendar
and POSIX time in single object.

Also I strongly encourage users to put as much information
to format as possible where

   std::cout << format(translate("Today is {1,date}")) % dt;

Over

   std::cout << translate("Today is:") << as::date << dt;

As translator can provide : "Today {1,ftime='%Y-%M-%d'}"
or something like or even more complex according to his
needs like "Today {1,date} ({1,locale=he_IL.UTF-8_at_calendar=hebrew,date})"
And display "Today Jan 1, 1970, (5 in Nissan 5770)"

So basically such information should be in formatting string.

>
> >>
> >> I'd hate if we had to do something like this:
> >>
> >> boost::format("Sensor Value (at %1%): %2$.2%") %
> >> (locale::format("{1,date_time}") % date) % value
> >>
> >
> > You can just do boost::locale::format("Sensor Value (at {1,dt}): {2,p=2}")
>
> Thats great, so it should be easy to integrate locale::format and
> boost::format, shouldn't it?
>
>

Integrate yes, but use same format no
as it requires reimplementing boost::format
functionality from the scratch as the approaches
are too different.

> >> Minimally I'd expect
> >>
> >> boost::date_time dt = ...;
> >> locale::format("Today is {1,date}.") % dt
> >> to work.
> >>
> >
> > There are several problems:
> >
> > 1. boost::date_time has its own formatter facets and they can't
> > be overridden
> > 2. The use of locale facets in Boost.DateTime is quite incorrect.
> >
>
> Ok I'd settle for this:
>
> boost::date_time dt = ...;
> boost::locale::date_time ldt = dt;
> locale::format("Today is {1,date}.") % ldt
>
> or
> locale::format("Today is {1,date}.") % locale::date_time(dt)
>

There is no boost::date_time there is only

  boost::date_time::date (without time at all)
and

  boost::date_time::ptime

which has unclear semantics whether it is UTC
or local time (which is quite wrong)
as ptime can be created from locale_time clock
and universal_time clock

  (How POSIX time can be local time? It is same as PI=6.28
   but this is different story...)

So you need to convert it explicitly and the reasonable way
is up to you.

>
>
> > It is not that simple.
> >
> > I think it can be worked out together with cooperation
> > of Boost.DateTime author/maintainer.
> >
>
> Yes, that was kind of the Idea.
>

Of course it can be resolved in future, but
with current implementation of boost::Date_time
it is not that simple.

> Regards
>
> Fabio
>
>
>

Artyom
>


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