We should use gettext.
authorRoy Marples <roy@marples.name>
Sun, 25 Jan 2009 11:55:45 +0000 (11:55 +0000)
committerRoy Marples <roy@marples.name>
Sun, 25 Jan 2009 11:55:45 +0000 (11:55 +0000)
dhcpcd-gtk.h
main.c
menu.c

index 326acbbd37df2875212e24814d6bcc15dae88b33..f5541076a4f5686be567b321b5ce3d0a58873688 100644 (file)
 #include <arpa/inet.h>
 
 #include <dbus/dbus-glib.h>
+#include <glib.h>
+#include <glib/gi18n.h>
 #include <gtk/gtk.h>
+#include <libintl.h>
 
 #include "config.h"
 
diff --git a/main.c b/main.c
index 0918a72e4439deee87a6c66447198e87b705a0eb..e82ccad7d343ee4dc70da31367f5988fd74798df 100644 (file)
--- a/main.c
+++ b/main.c
@@ -28,6 +28,7 @@
  * maybe use network-idle -> network-transmit ->
  * network-receive -> network-transmit-receive */
 
+#include <locale.h>
 #include <stdlib.h>
 #include <string.h>
 
@@ -172,27 +173,27 @@ print_if_msg(const struct if_msg *ifm)
        showip = TRUE;
        showssid = FALSE;
        if (if_up(ifm))
-               reason = "Acquired address";
+               reason = N_("Acquired address");
        else {
                if (g_strcmp0(ifm->reason, "EXPIRE") == 0)
-                       reason = "Failed to renew";
+                       reason = N_("Failed to renew");
                else if (g_strcmp0(ifm->reason, "CARRIER") == 0) {
                        if (ifm->wireless) {
-                               reason = "Asssociated with";
+                               reason = N_("Asssociated with");
                                if (ifm->ssid != NULL)
                                        showssid = TRUE;
                        } else
-                               reason = "Cable plugged in";
+                               reason = N_("Cable plugged in");
                        showip = FALSE;
                } else if (g_strcmp0(ifm->reason, "NOCARRIER") == 0) {
                        if (ifm->wireless) {
                                if (ifm->ssid != NULL || ifm->ip.s_addr != 0) {
-                                       reason = "Lost association with";
+                                       reason = N_("Lost association with");
                                        showssid = TRUE;
                                } else
-                                   reason = "Not associated";
+                                   reason = N_("Not associated");
                        } else
-                               reason = "Cable unplugged";
+                               reason = N_("Cable unplugged");
                        showip = FALSE;
                }
        }
@@ -358,23 +359,23 @@ dhcpcd_event(_unused DBusGProxy *proxy, GHashTable *config, _unused void *data)
        msg = print_if_msg(ifm);
        title = NULL;
        if (if_up(ifm))
-               act = "Connected to ";
+               act = N_("Connected to ");
        else
                act = NULL;
        for (r = down_reasons; *r; r++) {
                if (g_strcmp0(*r, ifm->reason) == 0) {
-                       act = "Disconnected from ";
+                       act = N_("Disconnected from ");
                        break;
                }
        }
        if (act && ifm->ip.s_addr) {
                ipn = htonl(ifm->ip.s_addr);
                if (IN_LINKLOCAL(ipn))
-                       net = "private network";
+                       net = N_("private network");
                else if (IN_PRIVATE(ipn))
-                       net = "LAN";
+                       net = N_("LAN");
                else
-                       net = "internet";
+                       net = N_("internet");
                title = g_strconcat(act, net, NULL);
        }
 
@@ -450,9 +451,9 @@ check_status(const char *status)
                g_list_free(interfaces);
                interfaces = NULL;
                update_online(NULL);
-               msg = last? "Connection to dhcpcd lost" : "dhcpcd not running";
+               msg = N_(last? "Connection to dhcpcd lost" : "dhcpcd not running");
                gtk_status_icon_set_tooltip(status_icon, msg);
-               notify("No network", msg, GTK_STOCK_NETWORK);
+               notify(_("No network"), msg, GTK_STOCK_NETWORK);
        }
 
        refresh = FALSE;
@@ -473,8 +474,8 @@ check_status(const char *status)
        if (!dbus_g_proxy_call(dbus, "GetDhcpcdVersion", &error,
                               G_TYPE_INVALID,
                               G_TYPE_STRING, &version, G_TYPE_INVALID))
-               error_exit("GetDhcpcdVersion", error);
-       g_message("Connected to dhcpcd-%s", version);
+               error_exit(_("GetDhcpcdVersion"), error);
+       g_message(_("Connected to %s-%s"), "dhcpcd", version);
        g_free(version);
        dhcpcd_get_interfaces();
 }
@@ -493,28 +494,34 @@ main(int argc, char *argv[])
        char *version = NULL;
        GType otype;
        int tries = 5;
-       
+
+               
+       setlocale(LC_ALL, "");
+       bindtextdomain(PACKAGE, NULL);
+       bind_textdomain_codeset(PACKAGE, "UTF-8");
+       textdomain(PACKAGE); 
+
        gtk_init(&argc, &argv);
        g_set_application_name("dhcpcd Monitor");
        status_icon = gtk_status_icon_new_from_icon_name("network-offline");
        if (status_icon == NULL)
                status_icon = gtk_status_icon_new_from_stock(GTK_STOCK_DISCONNECT);
        
-       gtk_status_icon_set_tooltip(status_icon, "Connecting to dhcpcd ...");
+       gtk_status_icon_set_tooltip(status_icon, _("Connecting to dhcpcd ..."));
        gtk_status_icon_set_visible(status_icon, TRUE);
 
        notify_init(PACKAGE);
 
-       g_message("Connecting to dbus ...");
+       g_message(_("Connecting to dbus ..."));
        bus = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error);
        if (bus == NULL || error != NULL)
-               error_exit("Could not connect to system bus", error);
+               error_exit(_("Could not connect to system bus"), error);
        dbus = dbus_g_proxy_new_for_name(bus,
                                              DHCPCD_SERVICE,
                                              DHCPCD_PATH,
                                              DHCPCD_SERVICE);
 
-       g_message("Connecting to dhcpcd-dbus ...");
+       g_message(_("Connecting to dhcpcd-dbus ..."));
        while (--tries > 0) {
                g_clear_error(&error);
                if (dbus_g_proxy_call_with_timeout(dbus,
@@ -528,18 +535,18 @@ main(int argc, char *argv[])
                        break;
        }
        if (tries == 0)
-               error_exit("GetVersion", error);
-       g_message("Connected to dhcpcd-dbus-%s", version);
+               error_exit(_("GetVersion"), error);
+       g_message(_("Connected to %s-%s"), "dhcpcd-dbus", version);
        g_free(version);
 
-       gtk_status_icon_set_tooltip(status_icon, "Triggering dhcpcd ...");
+       gtk_status_icon_set_tooltip(status_icon, _("Triggering dhcpcd ..."));
        online = FALSE;
        menu_init(status_icon);
 
        if (!dbus_g_proxy_call(dbus, "GetStatus", &error,
                               G_TYPE_INVALID,
                               G_TYPE_STRING, &version, G_TYPE_INVALID))
-               error_exit("GetStatus", error);
+               error_exit(_("GetStatus"), error);
        check_status(version);
        g_free(version);
 
diff --git a/menu.c b/menu.c
index 90471c143fe8c196c05be1c8d2d3abe250e1edad..45c8e5bc186699eebae37869ac1a68606b87c7e6 100644 (file)
--- a/menu.c
+++ b/menu.c
@@ -33,18 +33,16 @@ static const char *authors[] = {
        "Roy Marples <roy@marples.name>",
        NULL
 };
-static const char *license =
-       "Licensed under the 2 clause BSD license.\n"
-       "\n"
+static const char *license[] = {
+       "Licensed under the 2 clause BSD license.\n",
        "Redistribution and use in source and binary forms, with or without\n"
        "modification, are permitted provided that the following conditions\n"
-       "are met:\n"
+       "are met:\n",
        "1. Redistributions of source code must retain the above copyright\n"
-       "   notice, this list of conditions and the following disclaimer.\n"
+       "   notice, this list of conditions and the following disclaimer.\n",
        "2. Redistributions in binary form must reproduce the above copyright\n"
        "   notice, this list of conditions and the following disclaimer in the\n"
-       "   documentation and/or other materials provided with the distribution.\n"
-       "\n"
+       "   documentation and/or other materials provided with the distribution.\n",
        "THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND\n"
        "ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n"
        "IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\n"
@@ -55,7 +53,9 @@ static const char *license =
        "HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\n"
        "LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\n"
        "OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\n"
-       "SUCH DAMAGE.";
+       "SUCH DAMAGE.",
+       NULL
+};
 
 static void
 on_quit(_unused GtkMenuItem *item, _unused gpointer data)
@@ -96,19 +96,27 @@ url_hook(GtkAboutDialog *dialog, const char *url, _unused gpointer p)
 static void
 on_about(_unused GtkMenuItem *item, _unused gpointer data)
 {
+       char *l;
+
+       l = g_strconcat(_(license[0]), "\n",
+                       _(license[1]), "\n",
+                       _(license[2]), "\n",
+                       _(license[3]), "\n",
+                       _(license[4]), "\n",
+                       NULL);
        gtk_window_set_default_icon_name(GTK_STOCK_NETWORK);
        gtk_about_dialog_set_email_hook(email_hook, NULL, NULL);
        gtk_about_dialog_set_url_hook(url_hook, NULL, NULL);
        gtk_show_about_dialog(NULL,
                              "version", VERSION,
                              "copyright", copyright,
-                             "license", license,
+                             "license", l,
                              "website-label", "dhcpcd Website",
                              "website", "http://roy.marples.name/projects/dhcpcd",
                              "authors", authors,
-                             "wrap-license", TRUE,
                              "logo-icon-name", GTK_STOCK_NETWORK,
                              NULL);
+       g_free(l);
 }
 
 static void
@@ -183,7 +191,7 @@ on_popup(GtkStatusIcon *icon, guint button, guint32 atime, gpointer data)
 
        menu = (GtkMenu *)gtk_menu_new();
 
-       item = gtk_image_menu_item_new_with_mnemonic("_Quit");
+       item = gtk_image_menu_item_new_with_mnemonic(_("_Quit"));
        image = gtk_image_new_from_icon_name(GTK_STOCK_QUIT,
                                             GTK_ICON_SIZE_MENU);
        gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item), image);
@@ -194,7 +202,7 @@ on_popup(GtkStatusIcon *icon, guint button, guint32 atime, gpointer data)
        item = gtk_separator_menu_item_new();
        gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
 
-       item = gtk_image_menu_item_new_with_mnemonic("_Help");
+       item = gtk_image_menu_item_new_with_mnemonic(_("_Help"));
        image = gtk_image_new_from_icon_name(GTK_STOCK_HELP,
                                             GTK_ICON_SIZE_MENU);
        gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item), image);
@@ -202,7 +210,7 @@ on_popup(GtkStatusIcon *icon, guint button, guint32 atime, gpointer data)
                         G_CALLBACK(on_help), icon);
        gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
 
-       item = gtk_image_menu_item_new_with_mnemonic("_About");
+       item = gtk_image_menu_item_new_with_mnemonic(_("_About"));
        image = gtk_image_new_from_icon_name(GTK_STOCK_ABOUT,
                                             GTK_ICON_SIZE_MENU);
        gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item), image);