aboutsummaryrefslogtreecommitdiff
path: root/src/examples
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2017-03-21 12:36:53 +0100
committerChristian Grothoff <christian@grothoff.org>2017-03-21 14:15:52 +0100
commitd14c6aa0f7dfc3b950a9c0c8ef218b6ba4aa4725 (patch)
treedd5373ce803f543ca17047ec9e27abb1b6c31b97 /src/examples
parentf3dd2a630369473fe3bc0ac86983e59f64457a97 (diff)
downloadlibmicrohttpd-d14c6aa0f7dfc3b950a9c0c8ef218b6ba4aa4725.tar.gz
libmicrohttpd-d14c6aa0f7dfc3b950a9c0c8ef218b6ba4aa4725.zip
style fixes to i18n example
Diffstat (limited to 'src/examples')
-rwxr-xr-xsrc/examples/msgs_i18n.c78
1 files changed, 44 insertions, 34 deletions
diff --git a/src/examples/msgs_i18n.c b/src/examples/msgs_i18n.c
index 220729af..2d8eb566 100755
--- a/src/examples/msgs_i18n.c
+++ b/src/examples/msgs_i18n.c
@@ -19,7 +19,8 @@
19/** 19/**
20 * @file msgs_i18n.c 20 * @file msgs_i18n.c
21 * @brief example for how to use translate libmicrohttpd messages 21 * @brief example for how to use translate libmicrohttpd messages
22 * @author Christian Grothoff, Silvio Clecio (silvioprog) 22 * @author Christian Grothoff
23 * @author Silvio Clecio (silvioprog)
23 */ 24 */
24 25
25/* 26/*
@@ -35,51 +36,60 @@
35 * export LANGUAGE=pt_BR 36 * export LANGUAGE=pt_BR
36 * ./msgs_i18n 37 * ./msgs_i18n
37 * # it may print: Opção inválida 4196490! (Você terminou a lista com MHD_OPTION_END?) 38 * # it may print: Opção inválida 4196490! (Você terminou a lista com MHD_OPTION_END?)
38 *
39 * # tip: if you get any problem in your i18n application, you can debug it using `strace` tool, e.g:
40 * $ strace -e trace=open ./msgs_i18n
41 *
42 */ 39 */
43
44#include <stdio.h> 40#include <stdio.h>
45#include <locale.h> 41#include <locale.h>
46#include <libintl.h> 42#include <libintl.h>
47#include <microhttpd.h> 43#include <microhttpd.h>
48 44
49#ifndef _
50#define _(fm) dgettext("libmicrohttpd", fm)
51#endif
52 45
53static int 46static int
54ahc_echo(void *cls, 47ahc_echo (void *cls,
55 struct MHD_Connection *cnc, 48 struct MHD_Connection *cnc,
56 const char *url, 49 const char *url,
57 const char *mt, 50 const char *mt,
58 const char *ver, 51 const char *ver,
59 const char *upd, 52 const char *upd,
60 size_t *upsz, 53 size_t *upsz,
61 void **ptr) { 54 void **ptr)
62 return MHD_NO; 55{
56 return MHD_NO;
63} 57}
64 58
59
65static void 60static void
66error_handler(void *cls, 61error_handler (void *cls,
67 const char *fm, 62 const char *fm,
68 va_list ap) { 63 va_list ap)
69 vprintf(_(fm), ap); 64{
65 /* Here we do the translation using GNU gettext.
66 As the error message is from libmicrohttpd, we specify
67 "libmicrohttpd" as the translation domain here. */
68 vprintf (dgettext ("libmicrohttpd",
69 fm),
70 ap);
70} 71}
71 72
73
72int 74int
73main() { 75main (int argc,
74 setlocale(LC_ALL, ""); 76 char **argv)
75 /* notice I'm using PO files in the directory "libmicrohttpd/src/examples/locale", please change it matching 77{
76 * where the MHD PO files are installed */ 78 setlocale(LC_ALL, "");
77 bindtextdomain("libmicrohttpd", "locale"); 79
78 MHD_start_daemon(MHD_USE_SELECT_INTERNALLY | MHD_FEATURE_MESSAGES | MHD_USE_ERROR_LOG, 80 /* The example uses PO files in the directory
79 8080, 81 "libmicrohttpd/src/examples/locale". This
80 NULL, NULL, 82 needs to be adapted to match
81 &ahc_echo, NULL, 83 where the MHD PO files are installed. */
82 MHD_OPTION_EXTERNAL_LOGGER, &error_handler, NULL 84 bindtextdomain ("libmicrohttpd",
83 /* MHD_OPTION_END - to raise the error "Invalid option ..." we are going to translate */); 85 "locale");
84 return 1; /* purposely */ 86 MHD_start_daemon (MHD_USE_SELECT_INTERNALLY | MHD_FEATURE_MESSAGES | MHD_USE_ERROR_LOG,
87 8080,
88 NULL, NULL,
89 &ahc_echo, NULL,
90 MHD_OPTION_EXTERNAL_LOGGER, &error_handler, NULL,
91 99999 /* invalid option, to raise the error
92 "Invalid option ..." which we are going
93 to translate */);
94 return 1; /* This program won't "succeed"... */
85} 95}