mirror of
https://github.com/transmission/transmission.git
synced 2025-12-24 20:35:36 +00:00
Add internationalization support for the GTK GUI.
This commit is contained in:
83
gtk/main.c
83
gtk/main.c
@@ -34,6 +34,9 @@
|
||||
#include <unistd.h>
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
#include <glib/gi18n.h>
|
||||
|
||||
#include "defines.h"
|
||||
|
||||
#include "conf.h"
|
||||
#include "dialogs.h"
|
||||
@@ -142,20 +145,20 @@ enum listfrom { FROM_BUTTON, FROM_POPUP };
|
||||
struct { const gchar *name; const gchar *id; enum listact act; gboolean nomenu;
|
||||
int avail; const char *ttext; const char *tpriv; }
|
||||
actionitems[] = {
|
||||
{"Add", GTK_STOCK_ADD, ACT_OPEN, FALSE, 0,
|
||||
"Add a new torrent file", "XXX"},
|
||||
{"Start", GTK_STOCK_EXECUTE, ACT_START, FALSE,
|
||||
{N_("Add"), GTK_STOCK_ADD, ACT_OPEN, FALSE, 0,
|
||||
N_("Add a new torrent"), "XXX"},
|
||||
{N_("Start"), GTK_STOCK_EXECUTE, ACT_START, FALSE,
|
||||
(TR_STATUS_STOPPING | TR_STATUS_PAUSE),
|
||||
"Resume a torrent that has been paused", "XXX"},
|
||||
{"Stop", GTK_STOCK_STOP, ACT_STOP, FALSE,
|
||||
N_("Start a torrent that is not running"), "XXX"},
|
||||
{N_("Stop"), GTK_STOCK_STOP, ACT_STOP, FALSE,
|
||||
~(TR_STATUS_STOPPING | TR_STATUS_PAUSE),
|
||||
"Pause a torrent", "XXX"},
|
||||
{"Remove", GTK_STOCK_REMOVE, ACT_DELETE, FALSE, ~0,
|
||||
"Remove a torrent from the list", "XXX"},
|
||||
{"Properties", GTK_STOCK_PROPERTIES, ACT_INFO, FALSE, ~0,
|
||||
"Get additional information for a torrent", "XXX"},
|
||||
{"Preferences", GTK_STOCK_PREFERENCES, ACT_PREF, TRUE, 0,
|
||||
"Open preferences dialog", "XXX"},
|
||||
N_("Stop a torrent that is running"), "XXX"},
|
||||
{N_("Remove"), GTK_STOCK_REMOVE, ACT_DELETE, FALSE, ~0,
|
||||
N_("Remove a torrent"), "XXX"},
|
||||
{N_("Properties"), GTK_STOCK_PROPERTIES, ACT_INFO, FALSE, ~0,
|
||||
N_("Show additional information about a torrent"), "XXX"},
|
||||
{N_("Preferences"), GTK_STOCK_PREFERENCES, ACT_PREF, TRUE, 0,
|
||||
N_("Customize application behavior"), "XXX"},
|
||||
};
|
||||
|
||||
#define CBDATA_PTR "callback-data-pointer"
|
||||
@@ -170,7 +173,10 @@ main(int argc, char **argv) {
|
||||
|
||||
gtk_init(&argc, &argv);
|
||||
|
||||
g_set_application_name("Transmission");
|
||||
bindtextdomain("transmission-gtk", LOCALEDIR);
|
||||
textdomain("transmission-gtk");
|
||||
|
||||
g_set_application_name(_("Transmission"));
|
||||
|
||||
tr = tr_init();
|
||||
|
||||
@@ -415,9 +421,9 @@ makewind_toolbar(struct cbdata *data) {
|
||||
for(ii = 0; ii < ALEN(actionitems); ii++) {
|
||||
item = gtk_tool_button_new_from_stock(actionitems[ii].id);
|
||||
data->buttons[ii] = GTK_WIDGET(item);
|
||||
gtk_tool_button_set_label(GTK_TOOL_BUTTON(item), actionitems[ii].name);
|
||||
gtk_tool_button_set_label(GTK_TOOL_BUTTON(item), gettext(actionitems[ii].name));
|
||||
gtk_tool_item_set_tooltip(GTK_TOOL_ITEM(item), GTK_TOOLBAR(bar)->tooltips,
|
||||
actionitems[ii].ttext, actionitems[ii].tpriv);
|
||||
gettext(actionitems[ii].ttext), actionitems[ii].tpriv);
|
||||
g_object_set_data(G_OBJECT(item), LIST_ACTION,
|
||||
GINT_TO_POINTER(actionitems[ii].act));
|
||||
g_object_set_data(G_OBJECT(item), LIST_ACTION_FROM,
|
||||
@@ -450,6 +456,7 @@ makewind_list(struct cbdata *data) {
|
||||
GtkTreeViewColumn *col;
|
||||
GtkTreeSelection *sel;
|
||||
GtkCellRenderer *namerend, *progrend;
|
||||
char *str;
|
||||
|
||||
assert(MC_ROW_COUNT == ALEN(types));
|
||||
|
||||
@@ -461,14 +468,17 @@ makewind_list(struct cbdata *data) {
|
||||
data->view = GTK_TREE_VIEW(view);
|
||||
|
||||
namerend = gtk_cell_renderer_text_new();
|
||||
col = gtk_tree_view_column_new_with_attributes("Name", namerend, NULL);
|
||||
col = gtk_tree_view_column_new_with_attributes(_("Name"), namerend, NULL);
|
||||
gtk_tree_view_column_set_cell_data_func(col, namerend, dfname, NULL, NULL);
|
||||
gtk_tree_view_column_set_expand(col, TRUE);
|
||||
gtk_tree_view_append_column(GTK_TREE_VIEW(view), col);
|
||||
|
||||
progrend = tr_cell_renderer_torrent_new();
|
||||
g_object_set(progrend, "label", "<big> fnord fnord </big>", NULL);
|
||||
col = gtk_tree_view_column_new_with_attributes("Progress", progrend, NULL);
|
||||
/* this string is only used to determing the size of the progress bar */
|
||||
str = g_markup_printf_escaped("<big>%s</big>", _(" fnord fnord "));
|
||||
g_object_set(progrend, "label", str, NULL);
|
||||
g_free(str);
|
||||
col = gtk_tree_view_column_new_with_attributes(_("Progress"), progrend, NULL);
|
||||
gtk_tree_view_column_set_cell_data_func(col, progrend, dfprog, NULL, NULL);
|
||||
gtk_tree_view_append_column(GTK_TREE_VIEW(view), col);
|
||||
|
||||
@@ -543,17 +553,18 @@ dfname(GtkTreeViewColumn *col SHUTUP, GtkCellRenderer *rend,
|
||||
prog *= 100;
|
||||
|
||||
if(status & TR_STATUS_CHECK)
|
||||
top = g_strdup_printf("Checking existing files (%.1f%%)", prog);
|
||||
top = g_strdup_printf(_("Checking existing files (%.1f%%)"), prog);
|
||||
else if(status & TR_STATUS_DOWNLOAD)
|
||||
top = g_strdup_printf("Finishing in %02i:%02i:%02i (%.1f%%)",
|
||||
top = g_strdup_printf(_("Finishing in %02i:%02i:%02i (%.1f%%)"),
|
||||
eta / 60 / 60, eta / 60 % 60, eta % 60, prog);
|
||||
else if(status & TR_STATUS_SEED)
|
||||
top = g_strdup_printf("Seeding, uploading to %d of %d peer%s",
|
||||
dpeers, tpeers, (1 == tpeers ? "" : "s"));
|
||||
top = g_strdup_printf(ngettext("Seeding, uploading to %d of %d peer",
|
||||
"Seeding, uploading to %d of %d peers",
|
||||
tpeers), dpeers, tpeers);
|
||||
else if(status & TR_STATUS_STOPPING)
|
||||
top = g_strdup("Stopping...");
|
||||
top = g_strdup(_("Stopping..."));
|
||||
else if(status & TR_STATUS_PAUSE)
|
||||
top = g_strdup_printf("Paused (%.1f%%)", prog);
|
||||
top = g_strdup_printf(_("Stopped (%.1f%%)"), prog);
|
||||
else {
|
||||
top = g_strdup("");
|
||||
assert("XXX unknown status");
|
||||
@@ -561,12 +572,13 @@ dfname(GtkTreeViewColumn *col SHUTUP, GtkCellRenderer *rend,
|
||||
|
||||
if(status & TR_TRACKER_ERROR) {
|
||||
gtk_tree_model_get(model, iter, MC_ERR, &err, -1);
|
||||
bottom = g_strconcat("Error: ", err, NULL);
|
||||
bottom = g_strconcat(_("Error: "), err, NULL);
|
||||
g_free(err);
|
||||
}
|
||||
else if(status & TR_STATUS_DOWNLOAD)
|
||||
bottom = g_strdup_printf("Downloading from %i of %i peer%s",
|
||||
upeers, tpeers, (1 == tpeers ? "" : "s"));
|
||||
bottom = g_strdup_printf(ngettext("Downloading from %i of %i peer",
|
||||
"Downloading from %i of %i peers",
|
||||
tpeers), upeers, tpeers);
|
||||
else
|
||||
bottom = NULL;
|
||||
|
||||
@@ -583,7 +595,7 @@ dfname(GtkTreeViewColumn *col SHUTUP, GtkCellRenderer *rend,
|
||||
void
|
||||
dfprog(GtkTreeViewColumn *col SHUTUP, GtkCellRenderer *rend,
|
||||
GtkTreeModel *model, GtkTreeIter *iter, gpointer gdata SHUTUP) {
|
||||
char *dlstr, *ulstr, *str;
|
||||
char *dlstr, *ulstr, *str, *marked;
|
||||
gfloat prog, dl, ul;
|
||||
|
||||
/* XXX should I worry about gtk_tree_model_get failing? */
|
||||
@@ -596,11 +608,13 @@ dfprog(GtkTreeViewColumn *col SHUTUP, GtkCellRenderer *rend,
|
||||
|
||||
dlstr = readablesize(dl * 1024.0, 2);
|
||||
ulstr = readablesize(ul * 1024.0, 2);
|
||||
str = g_strdup_printf("<small>DL: %s/s\nUL: %s/s</small>", dlstr, ulstr);
|
||||
str = g_strdup_printf(_("DL: %s/s\nUL: %s/s"), dlstr, ulstr);
|
||||
marked = g_markup_printf_escaped("<small>%s</small>", str);
|
||||
g_object_set(rend, "text", str, "value", prog, NULL);
|
||||
g_free(dlstr);
|
||||
g_free(ulstr);
|
||||
g_free(str);
|
||||
g_free(marked);
|
||||
}
|
||||
|
||||
gboolean
|
||||
@@ -641,7 +655,8 @@ updatemodel(gpointer gdata) {
|
||||
tr_torrentRates(data->tr, &up, &down);
|
||||
downstr = readablesize(down * 1024.0, 2);
|
||||
upstr = readablesize(up * 1024.0, 2);
|
||||
str = g_strdup_printf(" Total DL: %s/s Total UL: %s/s", upstr, downstr);
|
||||
str = g_strdup_printf(_(" Total DL: %s/s Total UL: %s/s"),
|
||||
upstr, downstr);
|
||||
gtk_statusbar_pop(data->bar, 0);
|
||||
gtk_statusbar_push(data->bar, 0, str);
|
||||
g_free(str);
|
||||
@@ -734,7 +749,7 @@ dopopupmenu(GdkEventButton *event, struct cbdata *data,
|
||||
(actionitems[ii].avail &&
|
||||
(NULL == ids || !(actionitems[ii].avail & status))))
|
||||
continue;
|
||||
item = gtk_menu_item_new_with_label(actionitems[ii].name);
|
||||
item = gtk_menu_item_new_with_label(gettext(actionitems[ii].name));
|
||||
/* set the action for the menu item */
|
||||
g_object_set_data(G_OBJECT(item), LIST_ACTION,
|
||||
GINT_TO_POINTER(actionitems[ii].act));
|
||||
@@ -905,7 +920,8 @@ addtorrent(tr_handle_t *tr, GtkWindow *parentwind, const char *torrent,
|
||||
|
||||
if(NULL == dir && NULL != (dir = cf_getpref(PREF_DIR))) {
|
||||
if(!mkdir_p(dir, 0777)) {
|
||||
errmsg(parentwind, "Failed to create download directory %s:\n%s",
|
||||
errmsg(parentwind,
|
||||
_("An error occurred while creating directory %s:\n%s"),
|
||||
dir, strerror(errno));
|
||||
return FALSE;
|
||||
}
|
||||
@@ -916,7 +932,8 @@ addtorrent(tr_handle_t *tr, GtkWindow *parentwind, const char *torrent,
|
||||
if(0 != tr_torrentInit(tr, torrent)) {
|
||||
unblocksigs();
|
||||
/* XXX would be nice to have errno strings, are they printed to stdout? */
|
||||
errmsg(parentwind, "Failed to open torrent file %s", torrent);
|
||||
errmsg(parentwind,
|
||||
_("An error occurred while opening the torrent file %s"), torrent);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user