summaryrefslogtreecommitdiffstats
path: root/print.c
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2012-10-11 09:42:59 +0900
committerGravatar Dirk Hohndel <dirk@hohndel.org>2012-10-11 10:03:03 +0900
commit99846da77f960a72d615c82bf5c5881a2df83616 (patch)
tree1c55ef332daff3b69690bec6be7bd7d0a0a10387 /print.c
parenta2afe4128082b603add2b2be83f97ff78e0d0169 (diff)
downloadsubsurface-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 'print.c')
-rw-r--r--print.c33
1 files changed, 16 insertions, 17 deletions
diff --git a/print.c b/print.c
index 5adba94cd..1d4f68f07 100644
--- a/print.c
+++ b/print.c
@@ -1,3 +1,4 @@
+#include <glib/gi18n.h>
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
@@ -63,7 +64,7 @@ static void show_dive_text(struct dive *dive, cairo_t *cr, double w,
*divenr = 0;
if (dive->number)
- snprintf(divenr, sizeof(divenr), "Dive #%d - ", dive->number);
+ snprintf(divenr, sizeof(divenr), _("Dive #%d - "), dive->number);
utc_mkdate(dive->when, &tm);
len = snprintf(buffer, sizeof(buffer),
@@ -90,9 +91,7 @@ static void show_dive_text(struct dive *dive, cairo_t *cr, double w,
depth = get_depth_units(dive->maxdepth.mm, &decimals, &unit);
snprintf(buffer, sizeof(buffer),
- "Max depth: %.*f %s\n"
- "Duration: %d min\n"
- "%s",
+ _("Max depth: %.*f %s\nDuration: %d min\n%s"),
decimals, depth, unit,
(dive->duration.seconds+59) / 60,
people);
@@ -152,8 +151,8 @@ static void show_table_header(cairo_t *cr, double w, double h,
int i;
double maxwidth, maxheight, colwidth, curwidth;
PangoLayout *layout;
- char headers[7][80]= { "Dive#", "Date", "Depth", "Time", "Master",
- "Buddy", "Location" };
+ char headers[7][80]= { N_("Dive#"), N_("Date"), N_("Depth"), N_("Time"), N_("Master"),
+ N_("Buddy"), N_("Location") };
maxwidth = w * PANGO_SCALE;
maxheight = h * PANGO_SCALE * 0.9;
@@ -177,7 +176,7 @@ static void show_table_header(cairo_t *cr, double w, double h,
pango_layout_set_width(layout, colwidth);
curwidth = curwidth + colwidth;
}
- pango_layout_set_text(layout, headers[i], -1);
+ pango_layout_set_text(layout, _(headers[i]), -1);
pango_layout_set_justify(layout, 1);
pango_cairo_show_layout(cr, layout);
}
@@ -250,7 +249,7 @@ static void show_dive_table(struct dive *dive, cairo_t *cr, double w,
// Col 4: Time
len = snprintf(buffer, sizeof(buffer),
- "%d min",(dive->duration.seconds+59) / 60);
+ _("%d min"),(dive->duration.seconds+59) / 60);
cairo_move_to(cr, curwidth / PANGO_SCALE, 0);
pango_layout_set_width(layout, colwidth/ (double) 2);
pango_layout_set_text(layout, buffer, len);
@@ -472,21 +471,21 @@ static GtkWidget *print_dialog(GtkPrintOperation *operation, gpointer user_data)
{
GtkWidget *vbox, *radio1, *radio2, *frame, *box;
int dives;
- gtk_print_operation_set_custom_tab_label(operation, "Dive details");
+ gtk_print_operation_set_custom_tab_label(operation, _("Dive details"));
vbox = gtk_vbox_new(TRUE, 5);
- frame = gtk_frame_new("Print type");
+ frame = gtk_frame_new(_("Print type"));
gtk_box_pack_start(GTK_BOX(vbox), frame, FALSE, FALSE, 1);
box = gtk_hbox_new(FALSE, 2);
gtk_container_add(GTK_CONTAINER(frame), box);
- radio1 = gtk_radio_button_new_with_label (NULL, "Pretty print");
+ radio1 = gtk_radio_button_new_with_label (NULL, _("Pretty print"));
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(radio1),
print_options.type == PRETTY);
radio2 = gtk_radio_button_new_with_label_from_widget (
- GTK_RADIO_BUTTON (radio1), "Table print");
+ GTK_RADIO_BUTTON (radio1), _("Table print"));
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(radio2),
print_options.type == TABLE);
gtk_box_pack_start (GTK_BOX (box), radio1, TRUE, TRUE, 0);
@@ -498,12 +497,12 @@ static GtkWidget *print_dialog(GtkPrintOperation *operation, gpointer user_data)
dives = nr_selected_dives();
print_options.print_selected = dives >= 1;
if (print_options.print_selected) {
- frame = gtk_frame_new("Print selection");
- gtk_box_pack_start(GTK_BOX(vbox), frame, FALSE, FALSE, 1);
- box = gtk_hbox_new(FALSE, 1);
- gtk_container_add(GTK_CONTAINER(frame), box);
+ frame = gtk_frame_new(_("Print selection"));
+ gtk_box_pack_start(GTK_BOX(vbox), frame, FALSE, FALSE, 1);
+ box = gtk_hbox_new(FALSE, 1);
+ gtk_container_add(GTK_CONTAINER(frame), box);
GtkWidget *button;
- button = gtk_check_button_new_with_label("Print only selected dives");
+ button = gtk_check_button_new_with_label(_("Print only selected dives"));
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button),
print_options.print_selected);
gtk_box_pack_start(GTK_BOX(box), button, FALSE, FALSE, 2);