diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2012-10-11 09:42:59 +0900 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2012-10-11 10:03:03 +0900 |
commit | 99846da77f960a72d615c82bf5c5881a2df83616 (patch) | |
tree | 1c55ef332daff3b69690bec6be7bd7d0a0a10387 /divelist.c | |
parent | a2afe4128082b603add2b2be83f97ff78e0d0169 (diff) | |
download | subsurface-99846da77f960a72d615c82bf5c5881a2df83616.tar.gz |
Conversion to gettext to allow localization
This is just the first step - convert the string literals, try to catch
all the places where this isn't possible and the program needs to convert
string constants at runtime (those are the N_ macros).
Add a very rough first German localization so I can at least test what I
have done. Seriously, I have never used a localized OS, so I am certain
that I have many of the 'standard' translations wrong. Someone please take
over :-)
Major issues with this:
- right now it hardcodes the search path for the message catalog to be
./locale - that's of course bogus, but it works well while doing initial
testing. Once the tooling support is there we just should use the OS
default.
- even though de_DE defaults to ISO-8859-15 (or ISO-8859-1 - the internets
can't seem to agree) I went with UTF-8 as that is what Gtk appears to
want to use internally. ISO-8859-15 encoded .mo files create funny
looking artefacts instead of Umlaute.
- no support at all in the Makefile - I was hoping someone with more
experience in how to best set this up would contribute a good set of
Makefile rules - likely this will help fix the first issue in that it
will also install the .mo file(s) in the correct place(s)
For now simply run
msgfmt -c -o subsurface.mo deutsch.po
to create the subsurface.mo file and then move it to
./locale/de_DE.UTF-8/LC_MESSAGES/subsurface.mo
If you make changes to the sources and need to add new strings to be
translated, this is what seems to work (again, should be tooled through
the Makefile):
xgettext -o subsurface-new.pot -s -k_ -kN_ --add-comments="++GETTEXT" *.c
msgmerge -s -U po/deutsch.po subsurface-new.pot
If you do this PLEASE do one commit that just has the new msgid as
changes in line numbers create a TON of diff-noise. Do changes to
translations in a SEPARATE commit.
- no testing at all on Windows or Mac
It builds on Windows :-)
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'divelist.c')
-rw-r--r-- | divelist.c | 60 |
1 files changed, 34 insertions, 26 deletions
diff --git a/divelist.c b/divelist.c index 3272cdfdc..baef39696 100644 --- a/divelist.c +++ b/divelist.c @@ -15,6 +15,7 @@ #include <string.h> #include <time.h> #include <math.h> +#include <glib/gi18n.h> #include "divelist.h" #include "dive.h" @@ -1254,18 +1255,18 @@ static struct divelist_column { int *visible; } dl_column[] = { [DIVE_NR] = { "#", nr_data_func, NULL, ALIGN_RIGHT | UNSORTABLE }, - [DIVE_DATE] = { "Date", date_data_func, NULL, ALIGN_LEFT }, + [DIVE_DATE] = { N_("Date"), date_data_func, NULL, ALIGN_LEFT }, [DIVE_RATING] = { UTF8_BLACKSTAR, star_data_func, NULL, ALIGN_LEFT }, - [DIVE_DEPTH] = { "ft", depth_data_func, NULL, ALIGN_RIGHT }, - [DIVE_DURATION] = { "min", duration_data_func, NULL, ALIGN_RIGHT }, + [DIVE_DEPTH] = { N_("ft"), depth_data_func, NULL, ALIGN_RIGHT }, + [DIVE_DURATION] = { N_("min"), duration_data_func, NULL, ALIGN_RIGHT }, [DIVE_TEMPERATURE] = { UTF8_DEGREE "F", temperature_data_func, NULL, ALIGN_RIGHT, &visible_cols.temperature }, - [DIVE_TOTALWEIGHT] = { "lbs", weight_data_func, NULL, ALIGN_RIGHT, &visible_cols.totalweight }, - [DIVE_SUIT] = { "Suit", NULL, NULL, ALIGN_LEFT, &visible_cols.suit }, - [DIVE_CYLINDER] = { "Cyl", NULL, NULL, 0, &visible_cols.cylinder }, + [DIVE_TOTALWEIGHT] = { N_("lbs"), weight_data_func, NULL, ALIGN_RIGHT, &visible_cols.totalweight }, + [DIVE_SUIT] = { N_("Suit"), NULL, NULL, ALIGN_LEFT, &visible_cols.suit }, + [DIVE_CYLINDER] = { N_("Cyl"), NULL, NULL, 0, &visible_cols.cylinder }, [DIVE_NITROX] = { "O" UTF8_SUBSCRIPT_2 "%", nitrox_data_func, nitrox_sort_func, 0, &visible_cols.nitrox }, - [DIVE_SAC] = { "SAC", sac_data_func, NULL, 0, &visible_cols.sac }, - [DIVE_OTU] = { "OTU", otu_data_func, NULL, 0, &visible_cols.otu }, - [DIVE_LOCATION] = { "Location", NULL, NULL, ALIGN_LEFT }, + [DIVE_SAC] = { N_("SAC"), sac_data_func, NULL, 0, &visible_cols.sac }, + [DIVE_OTU] = { N_("OTU"), otu_data_func, NULL, 0, &visible_cols.otu }, + [DIVE_LOCATION] = { N_("Location"), NULL, NULL, ALIGN_LEFT }, }; @@ -1998,8 +1999,12 @@ static void delete_dive_cb(GtkWidget *menuitem, GtkTreePath *path) static void popup_divelist_menu(GtkTreeView *tree_view, GtkTreeModel *model, int button, GdkEventButton *event) { GtkWidget *menu, *menuitem, *image; - char editlabel[] = "Edit dives"; - char deletelabel[] = "Delete dives"; + char editplurallabel[] = N_("Edit dives"); + char editsinglelabel[] = N_("Edit dive"); + char *editlabel; + char deleteplurallabel[] = N_("Delete dives"); + char deletesinglelabel[] = N_("Delete dive"); + char *deletelabel; GtkTreePath *path, *prevpath, *nextpath; GtkTreeIter iter, previter, nextiter; int idx, previdx, nextidx; @@ -2011,7 +2016,7 @@ static void popup_divelist_menu(GtkTreeView *tree_view, GtkTreeModel *model, int gtk_tree_model_get(MODEL(dive_list), &iter, DIVE_INDEX, &idx, -1); menu = gtk_menu_new(); - menuitem = gtk_image_menu_item_new_with_label("Add dive"); + menuitem = gtk_image_menu_item_new_with_label(_("Add dive")); image = gtk_image_new_from_stock(GTK_STOCK_ADD, GTK_ICON_SIZE_MENU); gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(menuitem), image); g_signal_connect(menuitem, "activate", G_CALLBACK(add_dive_cb), NULL); @@ -2019,7 +2024,7 @@ static void popup_divelist_menu(GtkTreeView *tree_view, GtkTreeModel *model, int if (idx < 0) { /* mouse pointer is on a trip summary entry */ - menuitem = gtk_menu_item_new_with_label("Edit Trip Summary"); + menuitem = gtk_menu_item_new_with_label(_("Edit Trip Summary")); g_signal_connect(menuitem, "activate", G_CALLBACK(edit_trip_cb), path); gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); prevpath = gtk_tree_path_copy(path); @@ -2027,7 +2032,7 @@ static void popup_divelist_menu(GtkTreeView *tree_view, GtkTreeModel *model, int gtk_tree_model_get_iter(MODEL(dive_list), &previter, prevpath)) { gtk_tree_model_get(MODEL(dive_list), &previter, DIVE_INDEX, &previdx, -1); if (previdx < 0) { - menuitem = gtk_menu_item_new_with_label("Merge trip with trip above"); + menuitem = gtk_menu_item_new_with_label(_("Merge trip with trip above")); g_signal_connect(menuitem, "activate", G_CALLBACK(merge_trips_cb), path); gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); } @@ -2037,12 +2042,12 @@ static void popup_divelist_menu(GtkTreeView *tree_view, GtkTreeModel *model, int if (gtk_tree_model_get_iter(MODEL(dive_list), &nextiter, nextpath)) { gtk_tree_model_get(MODEL(dive_list), &nextiter, DIVE_INDEX, &nextidx, -1); if (nextidx < 0) { - menuitem = gtk_menu_item_new_with_label("Merge trip with trip below"); + menuitem = gtk_menu_item_new_with_label(_("Merge trip with trip below")); g_signal_connect(menuitem, "activate", G_CALLBACK(merge_trips_cb), nextpath); gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); } } - menuitem = gtk_menu_item_new_with_label("Remove Trip"); + menuitem = gtk_menu_item_new_with_label(_("Remove Trip")); g_signal_connect(menuitem, "activate", G_CALLBACK(remove_trip_cb), path); gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); } else { @@ -2050,8 +2055,11 @@ static void popup_divelist_menu(GtkTreeView *tree_view, GtkTreeModel *model, int /* if we right click on selected dive(s), edit or delete those */ if (dive->selected) { if (amount_selected == 1) { - deletelabel[strlen(deletelabel) - 1] = '\0'; - editlabel[strlen(editlabel) - 1] = '\0'; + deletelabel = _(deletesinglelabel); + editlabel = _(editsinglelabel); + } else { + deletelabel = _(deleteplurallabel); + editlabel = _(editplurallabel); } menuitem = gtk_menu_item_new_with_label(deletelabel); g_signal_connect(menuitem, "activate", G_CALLBACK(delete_selected_dives_cb), path); @@ -2061,12 +2069,12 @@ static void popup_divelist_menu(GtkTreeView *tree_view, GtkTreeModel *model, int g_signal_connect(menuitem, "activate", G_CALLBACK(edit_selected_dives_cb), NULL); gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); } else { - deletelabel[strlen(deletelabel) - 1] = '\0'; + deletelabel = _(deletesinglelabel); menuitem = gtk_menu_item_new_with_label(deletelabel); g_signal_connect(menuitem, "activate", G_CALLBACK(delete_dive_cb), path); gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); - editlabel[strlen(editlabel) - 1] = '\0'; + editlabel = _(editsinglelabel); menuitem = gtk_menu_item_new_with_label(editlabel); g_signal_connect(menuitem, "activate", G_CALLBACK(edit_dive_from_path_cb), path); gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); @@ -2077,7 +2085,7 @@ static void popup_divelist_menu(GtkTreeView *tree_view, GtkTreeModel *model, int int *indices = gtk_tree_path_get_indices(path); /* top level dive or child dive that is not the first child */ if (depth == 1 || indices[1] > 0) { - menuitem = gtk_menu_item_new_with_label("Create new trip above"); + menuitem = gtk_menu_item_new_with_label(_("Create new trip above")); g_signal_connect(menuitem, "activate", G_CALLBACK(insert_trip_before_cb), path); gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); } @@ -2087,24 +2095,24 @@ static void popup_divelist_menu(GtkTreeView *tree_view, GtkTreeModel *model, int gtk_tree_path_prev(prevpath) && gtk_tree_model_get_iter(MODEL(dive_list), &previter, prevpath) && gtk_tree_model_iter_n_children(model, &previter)) { - menuitem = gtk_menu_item_new_with_label("Add to trip above"); + menuitem = gtk_menu_item_new_with_label(_("Add to trip above")); g_signal_connect(menuitem, "activate", G_CALLBACK(merge_dive_into_trip_above_cb), path); gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); } if (DIVE_IN_TRIP(dive)) { if (dive->selected && amount_selected > 1) - menuitem = gtk_menu_item_new_with_label("Remove selected dives from trip"); + menuitem = gtk_menu_item_new_with_label(_("Remove selected dives from trip")); else - menuitem = gtk_menu_item_new_with_label("Remove dive from trip"); + menuitem = gtk_menu_item_new_with_label(_("Remove dive from trip")); g_signal_connect(menuitem, "activate", G_CALLBACK(remove_from_trip_cb), path); gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); } } } - menuitem = gtk_menu_item_new_with_label("Expand all"); + menuitem = gtk_menu_item_new_with_label(_("Expand all")); g_signal_connect(menuitem, "activate", G_CALLBACK(expand_all_cb), tree_view); gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); - menuitem = gtk_menu_item_new_with_label("Collapse all"); + menuitem = gtk_menu_item_new_with_label(_("Collapse all")); g_signal_connect(menuitem, "activate", G_CALLBACK(collapse_all_cb), tree_view); gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); gtk_widget_show_all(menu); |