Re: setlocale() always returns "C"



On Aug 10, 5:51 pm, yogeshmk <yogesh.m.kulka...@xxxxxxxxx> wrote:
On Aug 10, 5:12 pm, Huibert Bol <huibert....@xxxxxxxxxxx> wrote:



yogeshmk wrote:
I'm writing an application which is required to function with many
languages and also compile on Linux & windows. Here's how I find the
locale ..

# include <stdio.h>
# include <locale.h>

int
main(void)
{
    unsigned char* loc = NULL;
    loc = setlocale(LC_MESSAGES, NULL);

    puts (loc);
    return 0;
}

I've ran this piece of code on RedHat linux (en_US.UTF-8), Windows XP
(??) and Ubuntu linux (on which the `locale` *command* returns
"en_IN.UTF-8" which is correct). However, I observe that the function
always returns "C" as the locale.

Q1. What explains this behaviour of 'setlocale()'
Q2. Any other way to find out the currently set language on the
computer?

A program's locale at startup will always be "C", so that's all you're going
to get without explicitly setting it to something else.

To change the current locale you want to use something like:

  setlocale(LC_MESSAGES, "");

 - Huibert.

--
Okay... really not something I needed to see.  --Raven

Ummm....I was under the impression that 'setlocale()' with second
param NULL will query and return the current locale of the OS.

If what you say is right, then I have to set the locale myself, but
the question is which? I don't know whether my program is running on a
computer with spanish locale settings so I need to print "Hola Terra!"
instead of "Hello World!"?

--
~yogesh kulkarni.

I anyway tried the setlocale() call again.

loc = setlocale(LC_ALL /* any LC_* catagories are ok here */, "" /
*instead of NULL */);

returns me the current locale set on my system.
Thanks for the reply.

cheers!
--
~ yogesh kulkarni.
.



Relevant Pages

  • Re: i18ned Character Set in DBMS and tables
    ... the fact that there is no Locale ... two-letter codes as defined by ISO-639. ... German people and we have understood each other 'einwandfrei'. ... > languages of this country: German, French and Italian, plus English), and ...
    (comp.lang.java.programmer)
  • Re: UCS Identifiers and compilers
    ... Some of their languages have both case ... context dependent glyphs for the same character, ... changed our locale between calls. ...
    (comp.compilers)
  • Re: Locale independence and grammatical structure
    ... in languages with inflections it's quite ... > Making a huge dictionary of all words in all possible contexts may ... So the program is not Locale ... of grammer or language. ...
    (comp.programming)
  • locale (was: Accented characters in less and vim)
    ... Most people would use both languages interchangably; ... hence the correct locale should not be taken from ... presumable has its very own character encoding). ... :> Shouldn't $LANG always include an encoding defintion? ...
    (uk.comp.os.linux)
  • Re: lsort -dictionary
    ... >> certainly not one that spans languages. ... >It's been well known for a long time that string collation is ... writing system to writing system, and that some other principles vary ... variation is not a function of locale. ...
    (comp.lang.tcl)