tags:

views:

200

answers:

1

Using the ICU library with C++ I'm doing:

char const *lang = Locale::getDefault().getLanguage();

If I write a small test program and run it on my Mac system, I get en for lang. However, inside a larger group project I'm working on, I get root. Anybody have any idea why? I did find this:

http://userguide.icu-project.org/locale/resources

so my guess is that, when running under the larger system, some ICU resources aren't being found, but I don't know what resources, why they're not being found, or how to fix it.

Additional Information

/usr/bin/locale returns:

LANG="en_US.ISO8859-1"
LC_COLLATE="C" 
LC_CTYPE="C" 
LC_MESSAGES="C" 
LC_MONETARY="C" 
LC_NUMERIC="C" 
LC_TIME="C" 
LC_ALL="C" 

If I write a small C program:

char const *lang = setlocale( LC_ALL, "" ):

I get en_US.ISO8859-1.

OS: Mac OS X 10.6.4 (Snow Leopard)
ICU version: 4.3.4 (latest available via MacPorts).

A little help? Thanks.

+1  A: 

root is surely an odd default locale - you don't see many native root-speakers these days.

But seriously, is it safe to assume on the larger system that someone hasn't called one of the variants of setDefault("root")?

What does something like /usr/bin/locale return on this system (if you can run that)?

ICU 4.4 now has a test program called 'icuinfo', does it also return root as the default locale?

What OS/platform is this on, and which version of ICU?

Steven R. Loomis
If you read the info at the link I provided, it explains the "root" locale. A simple grep through all the source code says that nobody has called setDefault.
Paul J. Lucas
Paul, I'm familiar with the root locale (and hope I did not put you off by my sarcastic first sentence). Thanks for your reply- I'll look into this a bit more on MacPorts.
Steven R. Loomis
(Hmm, I thought I wrote this answer already:)Can you run /usr/bin/locale from inside of the 'larger system'? Can you run u_init() as the larger system starts and report back which error code it gives?
Steven R. Loomis
I'm not sure how, but now everything in my environment has all the LC_ variables as well as LANG be "en_US.UTF-8". The same is true when I do a system(3) calling /usr/bin/locale from inside the larger app. Calling u_init() returns status 0 (no error). ICU still returns "root".
Paul J. Lucas
I did this on snow leopard, macports' ICU 4.3.4 #include <unicode/locid.h> #include <stdio.h> int main(int argc, const char *argv[]) { char const *lang = Locale::getDefault().getLanguage(); puts("lang="); puts(lang); return 0; }Then: `icu-config --cxx --ldflags --cppflags --cxxflags` -o tst tst.cpp LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8 `icu-config --invoke` ./tstAs you said it works OK from the command line - returns 'en'.Can you say any more about the larger system? Can you run the test as the first line of your larger system's main()?
Steven R. Loomis