LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices

Reply
 
Search this Thread
Old 11-04-2005, 04:33 AM   #1
mic
Member
 
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:
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, ""));
	perror("setlocale");
	
	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, 01:06 PM   #2
jim mcnamara
Member
 
Registered: May 2002
Posts: 964

Rep: Reputation: 34
Each locale is a separate file, you have to have the file installed in
/usr/lib/nls/loc/locales

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

Last edited by jim mcnamara; 11-04-2005 at 01:12 PM.
 
Old 11-08-2005, 04:49 AM   #3
mic
Member
 
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.
 
  


Reply


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 10:23 AM
Rhythmbox returns failed to activate the shell: (null) Minderbinder Linux - Software 0 06-04-2004 06:41 PM
When to use setlocale() ? biosx Programming 3 01-31-2004 07:04 AM
Kmalloc returns null iannou Linux - General 0 06-28-2003 11:36 AM
Allegro create_bitmap() returns NULL tommyclee Programming 1 05-31-2002 12:41 PM


All times are GMT -5. The time now is 09:55 PM.

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