From 210b1b5574afb381b87d6d34860009a905ed6848 Mon Sep 17 00:00:00 2001 From: Håkon Nessjøen Date: Tue, 28 Feb 2012 14:32:53 +0100 Subject: Added i18n support --- mndp.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'mndp.c') diff --git a/mndp.c b/mndp.c index 7f81545..1b070e2 100644 --- a/mndp.c +++ b/mndp.c @@ -16,6 +16,8 @@ with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ +#include +#include #include #include #include @@ -24,6 +26,8 @@ #include "protocol.h" #include "config.h" +#define _(String) gettext (String) + /* Protocol data direction, not used here, but obligatory for protocol.c */ unsigned char mt_direction_fromserver = 0; @@ -33,6 +37,10 @@ int main(int argc, char **argv) { struct sockaddr_in si_me, si_remote; unsigned char buff[MT_PACKET_LEN]; + setlocale(LC_ALL, ""); + bindtextdomain("mactelnet","/usr/share/locale"); + textdomain("mactelnet"); + /* Open a UDP socket handle */ sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); @@ -46,16 +54,16 @@ int main(int argc, char **argv) { /* Bind to specified address/port */ if (bind(sock, (struct sockaddr *)&si_me, sizeof(si_me))==-1) { - fprintf(stderr, "Error binding to %s:%d\n", inet_ntoa(si_me.sin_addr), MT_MNDP_PORT); + fprintf(stderr, _("Error binding to %s:%d\n"), inet_ntoa(si_me.sin_addr), MT_MNDP_PORT); return 1; } /* Write informative message to STDERR to make it easier to use the output in simple scripts */ - fprintf(stderr, "Searching for MikroTik routers... Abort with CTRL+C.\n"); + fprintf(stderr, _("Searching for MikroTik routers... Abort with CTRL+C.\n")); /* Set the socket to allow sending broadcast packets */ if (setsockopt(sock, SOL_SOCKET, SO_BROADCAST, &optval, sizeof (optval))==-1) { - fprintf(stderr, "Unable to send broadcast packets: Operating in receive only mode.\n"); + fprintf(stderr, _("Unable to send broadcast packets: Operating in receive only mode.\n")); } else { /* Request routers identify themselves */ unsigned int message = 0; @@ -65,7 +73,7 @@ int main(int argc, char **argv) { si_remote.sin_port = htons(MT_MNDP_PORT); si_remote.sin_addr.s_addr = htonl(INADDR_BROADCAST); if (sendto (sock, &message, sizeof (message), 0, (struct sockaddr *)&si_remote, sizeof(si_remote))==-1) { - fprintf(stderr, "Unable to send broadcast packet: Operating in receive only mode.\n"); + fprintf(stderr, _("Unable to send broadcast packet: Operating in receive only mode.\n")); } } @@ -74,7 +82,7 @@ int main(int argc, char **argv) { /* Wait for a UDP packet */ result = recvfrom(sock, buff, MT_PACKET_LEN, 0, 0, 0); if (result < 0) { - fprintf(stderr, "Error occured. aborting\n"); + fprintf(stderr, _("An error occured. aborting\n")); exit(1); } @@ -88,7 +96,7 @@ int main(int argc, char **argv) { printf(" (%s %s %s)", packet->platform, packet->version, packet->hardware); } if (packet->uptime > 0) { - printf(" up %d days %d hours", packet->uptime / 86400, packet->uptime % 86400 / 3600); + printf(_(" up %d days %d hours"), packet->uptime / 86400, packet->uptime % 86400 / 3600); } putchar('\n'); } -- cgit v1.2.3