
----- Original Message -----
From: Jookia <166291@gmail.com> To: boost@lists.boost.org Cc: Sent: Sunday, August 26, 2012 2:55 PM Subject: Re: [boost] [locale] Custom Gettext paths.
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
On 26/08/12 21:16, Artyom Beilis wrote: 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@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?
No, that means if you want to translate your application to the language that is not supported by the backend, you can.
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'.
You do this differently, you use gettext... std::string path = "data/" + gettext("en") + "/images/logo.png" And this way if the application is not translated to the locale's language it would get a logo from English locale, otherwise it would get the logo from the supported locale... More than that if the OS/backend does not support your locale you will still be able to get the correct logo - even if you translate the application to ancient Egyptian which should be "bad" for all means.
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?
No, you can't for example if you are using for example ru_RU.UTF-8 locale with POSIX backend, it would work on your machine but on some other ru_RU locale would not be configured and will not be loaded. This is something that is done in the run time, but yet you prefer to run the application rather than fail. Also it is not always possible to know if it 100% loaded. For example even in ICU backend under some locales the spellout would not actually spell because of lack of relevant CLDR data - and this happens even with common locales like Austrian (AFAIR) So should you "fail" or continue? Some locales may be not official but they are relevant, for example is there es_US.UTF-8 locale? (I don't actually know) but, Spanish is not official language of USA, so should such a locale fail or it is fine? What is actually failure, is it partial or full or what?
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.
Domain is what you actually know - this is your application name :-)
Thanks for you time, Jookia.
You are welcome. Artyom Beilis -------------- CppCMS - C++ Web Framework: http://cppcms.com/ CppDB - C++ SQL Connectivity: http://cppcms.com/sql/cppdb/