|
Packit |
875988 |
/*
|
|
Packit |
875988 |
This file is part of libmicrohttpd
|
|
Packit |
875988 |
Copyright (C) 2017 Christian Grothoff, Silvio Clecio (silvioprog)
|
|
Packit |
875988 |
|
|
Packit |
875988 |
This library is free software; you can redistribute it and/or
|
|
Packit |
875988 |
modify it under the terms of the GNU Lesser General Public
|
|
Packit |
875988 |
License as published by the Free Software Foundation; either
|
|
Packit |
875988 |
version 2.1 of the License, or (at your option) any later version.
|
|
Packit |
875988 |
|
|
Packit |
875988 |
This library is distributed in the hope that it will be useful,
|
|
Packit |
875988 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
875988 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
875988 |
Lesser General Public License for more details.
|
|
Packit |
875988 |
|
|
Packit |
875988 |
You should have received a copy of the GNU Lesser General Public
|
|
Packit |
875988 |
License along with this library; if not, write to the Free Software
|
|
Packit |
875988 |
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
Packit |
875988 |
*/
|
|
Packit |
875988 |
/**
|
|
Packit |
875988 |
* @file msgs_i18n.c
|
|
Packit |
875988 |
* @brief example for how to use translate libmicrohttpd messages
|
|
Packit |
875988 |
* @author Christian Grothoff
|
|
Packit |
875988 |
* @author Silvio Clecio (silvioprog)
|
|
Packit |
875988 |
*/
|
|
Packit |
875988 |
|
|
Packit |
875988 |
/*
|
|
Packit |
875988 |
* suposing you are in Brazil:
|
|
Packit |
875988 |
*
|
|
Packit |
875988 |
* # generate the PO file
|
|
Packit |
875988 |
* $ msginit --input=po/libmicrohttpd.pot --locale=pt_BR --output=libmicrohttpd.po
|
|
Packit |
875988 |
* # open the generated .po in any program like Poedit and translate the MHD messages; once done, let's go to the test:
|
|
Packit |
875988 |
* mkdir -p src/examples/locale/pt_BR/LC_MESSAGES
|
|
Packit |
875988 |
* mv libmicrohttpd.mo libmicrohttpd.po src/examples/locale/pt_BR/LC_MESSAGES
|
|
Packit |
875988 |
* cd src/examples/
|
|
Packit |
875988 |
* gcc -o msgs_i18n msgs_i18n.c -lmicrohttpd
|
|
Packit |
875988 |
* export LANGUAGE=pt_BR
|
|
Packit |
875988 |
* ./msgs_i18n
|
|
Packit |
875988 |
* # it may print: Opção inválida 4196490! (Você terminou a lista com MHD_OPTION_END?)
|
|
Packit |
875988 |
*/
|
|
Packit |
875988 |
#include <stdio.h>
|
|
Packit |
875988 |
#include <locale.h>
|
|
Packit |
875988 |
#include <libintl.h>
|
|
Packit |
875988 |
#include <microhttpd.h>
|
|
Packit |
875988 |
|
|
Packit |
875988 |
|
|
Packit |
875988 |
static int
|
|
Packit |
875988 |
ahc_echo (void *cls,
|
|
Packit |
875988 |
struct MHD_Connection *cnc,
|
|
Packit |
875988 |
const char *url,
|
|
Packit |
875988 |
const char *mt,
|
|
Packit |
875988 |
const char *ver,
|
|
Packit |
875988 |
const char *upd,
|
|
Packit |
875988 |
size_t *upsz,
|
|
Packit |
875988 |
void **ptr)
|
|
Packit |
875988 |
{
|
|
Packit |
875988 |
return MHD_NO;
|
|
Packit |
875988 |
}
|
|
Packit |
875988 |
|
|
Packit |
875988 |
|
|
Packit |
875988 |
static void
|
|
Packit |
875988 |
error_handler (void *cls,
|
|
Packit |
875988 |
const char *fm,
|
|
Packit |
875988 |
va_list ap)
|
|
Packit |
875988 |
{
|
|
Packit |
875988 |
/* Here we do the translation using GNU gettext.
|
|
Packit |
875988 |
As the error message is from libmicrohttpd, we specify
|
|
Packit |
875988 |
"libmicrohttpd" as the translation domain here. */
|
|
Packit |
875988 |
vprintf (dgettext ("libmicrohttpd",
|
|
Packit |
875988 |
fm),
|
|
Packit |
875988 |
ap);
|
|
Packit |
875988 |
}
|
|
Packit |
875988 |
|
|
Packit |
875988 |
|
|
Packit |
875988 |
int
|
|
Packit |
875988 |
main (int argc,
|
|
Packit |
875988 |
char **argv)
|
|
Packit |
875988 |
{
|
|
Packit |
875988 |
setlocale(LC_ALL, "");
|
|
Packit |
875988 |
|
|
Packit |
875988 |
/* The example uses PO files in the directory
|
|
Packit |
875988 |
"libmicrohttpd/src/examples/locale". This
|
|
Packit |
875988 |
needs to be adapted to match
|
|
Packit |
875988 |
where the MHD PO files are installed. */
|
|
Packit |
875988 |
bindtextdomain ("libmicrohttpd",
|
|
Packit |
875988 |
"locale");
|
|
Packit |
875988 |
MHD_start_daemon (MHD_USE_SELECT_INTERNALLY | MHD_FEATURE_MESSAGES | MHD_USE_ERROR_LOG,
|
|
Packit |
875988 |
8080,
|
|
Packit |
875988 |
NULL, NULL,
|
|
Packit |
875988 |
&ahc_echo, NULL,
|
|
Packit |
875988 |
MHD_OPTION_EXTERNAL_LOGGER, &error_handler, NULL,
|
|
Packit |
875988 |
99999 /* invalid option, to raise the error
|
|
Packit |
875988 |
"Invalid option ..." which we are going
|
|
Packit |
875988 |
to translate */);
|
|
Packit |
875988 |
return 1; /* This program won't "succeed"... */
|
|
Packit |
875988 |
}
|