summaryrefslogtreecommitdiff
path: root/tests/i18n/test_gettext.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/i18n/test_gettext.c')
-rw-r--r--tests/i18n/test_gettext.c86
1 files changed, 86 insertions, 0 deletions
diff --git a/tests/i18n/test_gettext.c b/tests/i18n/test_gettext.c
new file mode 100644
index 0000000..d5cb4c5
--- /dev/null
+++ b/tests/i18n/test_gettext.c
@@ -0,0 +1,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;
+}