472,800 Members | 1,652 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,800 software developers and data experts.

setlocale() always returns "C"

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;
}

Depending upon what string 'loc' contains, I need to write "hello
world" (or any other message) in the corrosponding language (there are
separate header files with texts in different languages coded in a
struct.

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?

cheers!
--
~ yogesh kulkarni.

Aug 10 '08 #1
5 5627
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
Aug 10 '08 #2
On Aug 10, 5:12*pm, Huibert Bol <huibert....@quicknet.nlwrote:
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.
Aug 10 '08 #3
yogeshmk wrote:
On Aug 10, 5:12*pm, Huibert Bol <huibert....@quicknet.nlwrote:
>To change the current locale you want to use something like:

setlocale(LC_MESSAGES, "");
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!"?
Using an empty string (like in the example above), will set the locale
"correctly". Under POSIX systems, for example, it will use the LC_*
environment variables.

--
Okay... really not something I needed to see. --Raven
Aug 10 '08 #4
On Aug 10, 5:51*pm, yogeshmk <yogesh.m.kulka...@gmail.comwrote:
On Aug 10, 5:12*pm, Huibert Bol <huibert....@quicknet.nlwrote:
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.
Aug 10 '08 #5
yogeshmk wrote:
On Aug 10, 5:12*pm, Huibert Bol <huibert....@quicknet.nlwrote:
>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!"?
You can usually get the locale being used from environment variables,
for example the LANG variable under Unix system. For more details ask
in a group targetting your system like comp.unix.programmer or
comp.os.ms-windows.programmer.win32, since C leaves it entirely upto
the implementation to assign the semantics for locales other than "C".
In a production program you'll probably want to use a tried and tested
internationalisation package rather than reinvent on your own.

Aug 10 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: build | last post by:
G'day All, I have a problem with this loop. There are a number of .txt files in 'myPath'. tmpFile = Dir(myPath & "\*.txt") 'PROCESS FOLDER Do Until tmpFile = "" <lottsa code> <too much to...
10
by: comp.lang.php | last post by:
echo mime_content_type('/var/www/html/video/small.mov'); // 1.5mb Quicktime video returns "video/quicktime" echo mime_content_type('/var/www/html/video/huge.mov'); // 10.5mb Quicktime video...
5
by: Tim | last post by:
Hello All, I am writing a program that checks for the NumLock status and turns the NumLock on if it is off. I'm not sure what I'm overlooking at this point, but the code will compile and run, but...
1
by: Tim | last post by:
Hello All, I am writing a program that checks for the NumLock status and turns the NumLock on if it is off. I'm not sure what I'm overlooking at this point, but the code will compile and run, but...
5
by: Dan C Douglas | last post by:
I have just installed VS.NET 2003 on my computer. I have a project that I have been developing on VS.NET 2002. I haven't upgraded this project to VS.NET 2003 yet and I am still developing it in...
7
by: Jim Carlock | last post by:
Does a SELECT element (listbox) need to be inside a FORM element? The code I'm playing with: <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"...
9
by: Klaus Johannes Rusch | last post by:
IE7 returns "unknown" instead of "undefined" when querying the type of an unknown property of an object, for example document.write(typeof window.missingproperty); Has "unknown" been defined...
3
by: robert.szczepanski | last post by:
Hi Everybody Why the following script return NULL? this is the following: <?php var_dump ( setlocale(LC_ALL, "pl") ); ?>
2
by: =?iso-8859-1?B?S2VyZW0gR/xtcvxrY/w=?= | last post by:
Hi, the topic says all. I use this code from C# to call the NtQuerySystemInformation. When i call NtQuerySystemInformation the first time with zero buffer length to get the buffer size needed...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.