[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] [libmicrohttpd] branch master updated: Added i18n example:
From: |
gnunet |
Subject: |
[GNUnet-SVN] [libmicrohttpd] branch master updated: Added i18n example: msgs_i18n.c |
Date: |
Tue, 28 Feb 2017 19:53:00 +0100 |
This is an automated email from the git hooks/post-receive script.
silvioprog pushed a commit to branch master
in repository libmicrohttpd.
The following commit(s) were added to refs/heads/master by this push:
new abb31c0a Added i18n example: msgs_i18n.c
abb31c0a is described below
commit abb31c0a77bdf16f247f0540e022f09fb8456eac
Author: silvioprog <address@hidden>
AuthorDate: Tue Feb 28 15:49:34 2017 -0300
Added i18n example: msgs_i18n.c
---
AUTHORS | 1 +
src/examples/Makefile.am | 6 ++++
src/examples/msgs_i18n.c | 91 ++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 98 insertions(+)
diff --git a/AUTHORS b/AUTHORS
index feb911e9..f927e0b0 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -56,6 +56,7 @@ Robert Groenenberg <address@hidden>
Denis Dowling <address@hidden>
Louis Benoit <address@hidden>
Flavio Coelin <address@hidden>
+Silvio Clecio <address@hidden>
Documentation contributions also came from:
Marco Maggi <address@hidden>
diff --git a/src/examples/Makefile.am b/src/examples/Makefile.am
index ee8918b8..0e211678 100644
--- a/src/examples/Makefile.am
+++ b/src/examples/Makefile.am
@@ -25,6 +25,7 @@ noinst_PROGRAMS = \
minimal_example_comet \
querystring_example \
timeout \
+ msgs_i18n \
fileserver_example \
fileserver_example_dirs \
fileserver_example_external_select \
@@ -73,6 +74,11 @@ timeout_SOURCES = \
timeout_LDADD = \
$(top_builddir)/src/microhttpd/libmicrohttpd.la
+msgs_i18n_SOURCEs = \
+ msgs_i18n.c
+msgs_i18n_LDADD = \
+ $(top_builddir)/src/microhttpd/libmicrohttpd.la
+
chunked_example_SOURCES = \
chunked_example.c
chunked_example_LDADD = \
diff --git a/src/examples/msgs_i18n.c b/src/examples/msgs_i18n.c
new file mode 100755
index 00000000..ed23d982
--- /dev/null
+++ b/src/examples/msgs_i18n.c
@@ -0,0 +1,91 @@
+/*
+ This file is part of libmicrohttpd
+ Copyright (C) 2017 Christian Grothoff, Silvio Clecio (silvioprog)
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
USA
+*/
+/**
+ * @file msgs_i18n.c
+ * @brief example for how to use translate libmicrohttpd messages
+ * @author Christian Grothoff, Silvio Clecio (silvioprog)
+ */
+
+/*
+ * suposing you are in the libmicrohttp root directory and the LANG is
`pt_BR`: *
+ *
+ * # generate the POT file
+ * $ xgettext --keyword=_ --language=C --add-comments --sort-output -o
libmicrohttpd.pot src/microhttpd/*.c
+ *
+ * # generate the PO file
+ * $ msginit --input=libmicrohttpd.pot --locale=pt_BR --output=libmicrohttpd.po
+ *
+ * # open the generated .po in any program like Poedit and translate the MHD
messages; once done, let's go to the test:
+ * mkdir -p src/examples/locale/pt_BR/LC_MESSAGES
+ * mv libmicrohttpd.mo libmicrohttpd.po src/examples/locale/pt_BR/LC_MESSAGES
+ * cd src/examples/
+ * gcc -o msgs_i18n msgs_i18n.c -lmicrohttpd
+ * export LANGUAGE=pt_BR
+ * ./msgs_i18n
+ * # it may print: Opção inválida 4196490! (Você terminou a lista com
MHD_OPTION_END?)
+ *
+ * # tip: if you get any problem in your i18n application, you can debug it
using `strace` tool, e.g:
+ * $ strace -e trace=open ./msgs_i18n
+ *
+ * That's all!
+ *
+ */
+
+#include <stdio.h>
+#include <locale.h>
+#include <libintl.h>
+#include <microhttpd.h>
+
+#ifndef _
+#define _(fm) dgettext("libmicrohttpd", fm)
+#endif
+
+static int
+ahc_echo(void *cls,
+ struct MHD_Connection *cnc,
+ const char *url,
+ const char *mt,
+ const char *ver,
+ const char *upd,
+ size_t *upsz,
+ void **ptr) {
+ return MHD_NO;
+}
+
+static void
+error_handler(void *cls,
+ const char *fm,
+ va_list ap) {
+ vprintf(_(fm), ap);
+}
+
+int
+main() {
+ setlocale(LC_ALL, "");
+ /* notice I'm using PO files in the directory
"libmicrohttpd/src/examples/locale", please change it matching
+ * where the MHD PO files are installed */
+ bindtextdomain("libmicrohttpd", "locale");
+ MHD_start_daemon(MHD_USE_SELECT_INTERNALLY | MHD_FEATURE_MESSAGES |
MHD_USE_ERROR_LOG,
+ 8080,
+ NULL, NULL,
+ &ahc_echo, NULL,
+ MHD_OPTION_EXTERNAL_LOGGER, &error_handler, NULL
+ /* MHD_OPTION_END - to raise the error "Invalid option ..." we are
going to translate */);
+ return 1; /* purposely */
+}
--
To stop receiving notification emails like this one, please contact
address@hidden
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] [libmicrohttpd] branch master updated: Added i18n example: msgs_i18n.c,
gnunet <=