1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
/*
Copyright (C) 2008 Andreas Baumann <abaumann@yahoo.com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "port/sys.h"
#include "port/string.h" /* for strerror_r */
#include "port/stdio.h" /* for puts, fprintf */
#include <stdlib.h> /* for exit, EXIT_SUCCESS, free */
#include <errno.h> /* for errno */
#include "port/gettext.h" /* for i18n */
int main( void ) {
char *loc;
char *bind_domain;
char *domain;
/* respect locale settings of the environment */
loc = setlocale( LC_ALL, "" );
if( loc == NULL ) {
fprintf( stderr, "Warning, can't set locale, let's hope localization works nevertheless.\n" );
} else {
printf( "Using locale %s\n", loc );
}
/* for testing here set the location of the message files,
* for standard installations this is /usr/share/locale
* (this we must do also for libraries, but just this)
*/
bind_domain = bindtextdomain( "test_gettext", "locale" );
if( bind_domain == NULL ) {
char buf[1024];
strerror_r( errno, buf, 1024 );
fprintf( stderr, "Error setting gettext bind domain: %s (%d)\n",
buf, errno );
} else {
printf( "Using bind domain %s\n", bind_domain );
}
/* set text domain so gettext function calls are retrieving the right
* string
*/
domain = textdomain( "test_gettext" );
if( domain == NULL ) {
char buf[1024];
strerror_r( errno, buf, 1024 );
fprintf( stderr, "Error setting gettext domain: %s (%d)\n",
buf, errno );
} else {
printf( "Using domain %s\n", domain );
}
/* dgettext instead of gettext in libraries? why? */
/* print something localized */
puts( _( "A message without parameters" ) );
/* croaks in older gcc because the format string is used with a function
* without __attribute__ format definitions, this may also depend on the
* age of gettext and libintl?
*/
printf( _( "A message with two parameters, a string %s and an integer %d\n" ),
"string_param", 47 );
/* try POSIX positional arguments, gives a
* test_gettext.c:79: warning: ISO C does not support %n$ operand number formats */
/* printf( _( "We must insert %1$d coins into %2$s" ),
55, "the box" );
*/
return EXIT_SUCCESS;
}
|