Boost logo

Boost :

Subject: Re: [boost] [locale] Custom Gettext paths.
From: Jookia (166291_at_[hidden])
Date: 2012-08-26 07:55:12


On 26/08/12 21:16, Artyom Beilis wrote:
> Boost.Locale tries to gradually fallback to some supported locale,
> for example of you use Boost.Locale on FreeBSD without ICU using libstdc++
> that only supported locales would be C or POSIX.
>
> On the other hand you should still be able to use encoding conversions
> and dictionaries. Maybe the numbers and dates would not be formatted
> according to the locale, but the messages would still work.
>
>> I don't know if it's possible, but I'd propose a function like
>> get_real_locale_name which returns the 'real' name, as in the actual
>> locale that's being used (as in a fall back if parts of the locale are
>> valid), or an empty string if the locale is invalid all together.
>>
>> get_real_locale("en_US.UTF-8") == "en_US.UTF-8"
>> get_real_locale("en_US.UTF-8_at_calender=asdfbadinputjkl") ==
>> "en_US.UTF-8"
>> get_real_locale("zh_CN.UTF-24") == ""
>>
>
> "Real-locale name" is backend dependent and not always 1-to-1 conversion.
>
> So you can assume that the name you had given is the locale name, however
> some flags may be ignored.
> ...
>
> What do you mean, do you have an example? locale::info parses locale names syntactically.

Hmm. Is it an exceptional case then that I can generate a locale with
the name 'BAD' then, and get a locale out that acts like English but has
the name 'BAD'? Is this an implementation detail?

I'm not an expert or even knowledgeable, so I guess I should ask:
Does this matter? Knowing what locale I'm actually using. Right now it
seems to just be an issue for code correctness, or something like trying
to open a specific file and having to check if the locale is valid, or
using the locale's name. Opening 'data/<locale name>/images/logo.png' or
something might end up bad with the BAD locale although it's English.

Another way to prevent my program from using 'bad' data, is to figure
out if the locale is valid. So, is there a way to test if a locale is
valid, without it falling back? I see that the 'BAD' locale will fall
back to 'en'.

Oh, and if this is bad practice to be pedantic about this topic, I'd
like to know so I can stop. It's just that in my unit tests, I can't
actually say if the locale I've created is the locale I wanted. So maybe
I'm approaching the problem wrong?

> boost::locale::info gives you this information.

It does? All I see is the language, country, variant, encoding and name.
This doesn't include the Gettext translation name or the domain.

>> Another small thing, which is probably intended in libstdc++, is that locale
>> generation will break if you have junk in LC_MESSAGES.
>
> Boost locale does not use environment variable LC_MESSAGES, unlike POSIX locales
> Boost.Locale does not break down to different categories. The order the locale name
> is taken is LANG, LC_ALL, LC_CTYPE (if I remember correctly)

Ah, so this is probably something to do with Linux then.

> Regards,
> Artyom Beilis

Thanks for you time,
Jookia.


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