Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 11-04-2005, 03:33 AM   #1
Registered: Jun 2005
Posts: 44

Rep: Reputation: 16
setlocale() returns NULL

I need to call setlocale to use gettext from my program. The target system where my program will run is busybox based embedded linux. I compiled busybox with enabled locale support.

This is the testing program code:
#include <libintl.h>
#include <locale.h>
#include <stdio.h>
#include <stdlib.h>

#define PACKAGE "hello"

int main(void)
	fprintf(stderr, "setlocale: \"%s\"\n", setlocale(LC_CTYPE, ""));
	fprintf(stderr, "setlocale: \"%s\"\n", setlocale(LC_MESSAGES, ""));
	fprintf(stderr, "bindtextdomain: \"%s\"\n", bindtextdomain(PACKAGE, "locale"));
	fprintf(stderr, "textdomain: \"%s\"\n\n", textdomain(PACKAGE));
	fprintf(stderr, gettext("Hello, world!\n"));
	return 0;
I created the mo file and put it in locale/xx/LC_MESSAGES/ in the program's directory.

On a normal desktop distro it works: "Hello world" is displayed in the correct translated language according to the environment variable LC_MESSAGES. On the target system it does not work. setlocale works only for C and POSIX. For others, even for en_US, it returns NULL and perror prints:
No such file or directory

Of course gettext then always returns only the original version of text.
I noticed it does not work also on Mepis linux on my desktop PC, although I have the locale packages installed. So I think this is probably not related to busybox/embedded linux

What I am supposed to do to make it work?
Old 11-04-2005, 12:06 PM   #2
jim mcnamara
Registered: May 2002
Posts: 964

Rep: Reputation: 36
Each locale is a separate file, you have to have the file installed in

From the shell
locale -a
shows them - if you have shell support in your OS.

Last edited by jim mcnamara; 11-04-2005 at 12:12 PM.
Old 11-08-2005, 03:49 AM   #3
Registered: Jun 2005
Posts: 44

Original Poster
Rep: Reputation: 16
Sorry for late reply... thank you for helping me. "locale -a" showed me what was wrong: I indeed did not have any locales installed but C and POSIX.

All locales take a lot of space and I cannot afford that. It took me a while before I figured out exactly which files I need and which not. It turned out the only file I really need is /usr/lib/locale/locale-archive. Even this one alone is enormous so I regenerated only the needed locales with locale-gen.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
setlocale pantera Programming 1 07-06-2004 09:23 AM
Rhythmbox returns failed to activate the shell: (null) Minderbinder Linux - Software 0 06-04-2004 05:41 PM
When to use setlocale() ? biosx Programming 3 01-31-2004 06:04 AM
Kmalloc returns null iannou Linux - General 0 06-28-2003 10:36 AM
Allegro create_bitmap() returns NULL tommyclee Programming 1 05-31-2002 11:41 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:18 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration