473,666 Members | 2,175 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_ME SSAGES, 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 5711
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_ME SSAGES, 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_ME SSAGES, "");

- Huibert.

--
Okay... really not something I needed to see. --Raven
Aug 10 '08 #2
On Aug 10, 5:12*pm, Huibert Bol <huibert....@qu icknet.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_ME SSAGES, 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_ME SSAGES, "");

*- 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....@qu icknet.nlwrote:
>To change the current locale you want to use something like:

setlocale(LC_ME SSAGES, "");
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.comwr ote:
On Aug 10, 5:12*pm, Huibert Bol <huibert....@qu icknet.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_ME SSAGES, 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_ME SSAGES, "");
*- 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_AL L /* 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....@qu icknet.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_ME SSAGES, 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_M ESSAGES, "");

- 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.progr ammer or
comp.os.ms-windows.program mer.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
internationalis ation 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
8224
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 post> tmpFile = Dir
10
4705
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 returns "text/plain" Environment: PHP 5.0.4 - Windows XP --enable-mime-magic PHP 4.3.11 - Fedora Core 4 --enable-mime-magic
5
5099
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 the SendInput call always returns "0". Here is some of the code: Beginning of Code... static extern uint SendInput(uint nInputs, ref INPUT pInputs, int cbSize);
1
1966
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 the SendInput call always returns "0". Here is some of the code: Beginning of Code... static extern uint SendInput(uint nInputs, ref INPUT pInputs, int cbSize);
5
2859
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 VS.NET 2002. When I am putting values from my SQLDataReader into labels and text boxes I am getting results such as 400.0000, or 25.90. For example... ? dr("CostsPerBin") returns
7
6890
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" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <!-- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
9
10720
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 as a valid return value for the typeof operator in a later version of ECMAScript or is this a JScript "feature"? -- Klaus Johannes Rusch
3
5227
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
3038
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 for the information i get a STATUS_INFO_LENGTH_MISMATCH which is -1073741820 in number, this is ok, but why does the function not store the required
0
8356
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8639
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7385
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5663
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4198
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4366
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2769
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2011
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1772
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.