S
Steven Woody
Hi,
I am in Linux writing a program using setlocale(3). But I found, only
the first invocation of setlocale(3) can be success, any subsequent
calling of this function will fail $B!J(B return NULL ) and the locale is
not changed. Is there any tip here?
Thanks.
#define _(String) gettext (String)
static void init_lc( const char* lc )
{
setlocale( LC_ALL, "" );
bindtextdomain( "hello", "/usr/local/share/locale" );
textdomain( "hello" );
}
int main( void )
{
init_lc( "" );
printf( _("Current locale is %s\n"), setlocale( LC_ALL, NULL ) );
printf( _("press 'e' to select English, 'c' to select Simplified
Chinese: ") );
int c;
while ( true ) {
c = getch();
if ( c == 'e' )
setlocale( "en_US" );
else if ( c == 'c' )
setlocale( "zh_CN" );
printf( _("press 'e' to select English, 'c' to select
Simplified Chinese: ") );
printf( _("Hello, world!\n") );
}
return 0;
}
I am in Linux writing a program using setlocale(3). But I found, only
the first invocation of setlocale(3) can be success, any subsequent
calling of this function will fail $B!J(B return NULL ) and the locale is
not changed. Is there any tip here?
Thanks.
#define _(String) gettext (String)
static void init_lc( const char* lc )
{
setlocale( LC_ALL, "" );
bindtextdomain( "hello", "/usr/local/share/locale" );
textdomain( "hello" );
}
int main( void )
{
init_lc( "" );
printf( _("Current locale is %s\n"), setlocale( LC_ALL, NULL ) );
printf( _("press 'e' to select English, 'c' to select Simplified
Chinese: ") );
int c;
while ( true ) {
c = getch();
if ( c == 'e' )
setlocale( "en_US" );
else if ( c == 'c' )
setlocale( "zh_CN" );
printf( _("press 'e' to select English, 'c' to select
Simplified Chinese: ") );
printf( _("Hello, world!\n") );
}
return 0;
}