From: Daiki Ueno Date: Thu, 8 Jan 2015 02:09:14 +0000 (+0900) Subject: examples: Make hello-c-gnome3 translator friendly X-Git-Tag: v0.19.5~93 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=abcef7b39a2b3e5dd2c963339ef00180dbd67677;p=thirdparty%2Fgettext.git examples: Make hello-c-gnome3 translator friendly Suggested by Benno Schulenberg in: . * hello-c-gnome3/hello.gschema.xml: Use "use-markup" property instead of "sensitive", to clarify the meaning of the extracted strings. * hello-c-gnome3/hello.c (HelloApplicationWindow): Rename the "label2" member to "label". (update_content): New function. (clicked_callback): Rename from quit_callback and call update_content instead of quitting. All callers changed. * hello-c-gnome3/hello.ui: Abolish the first label and put a translatable text inside the button. --- diff --git a/gettext-tools/examples/ChangeLog b/gettext-tools/examples/ChangeLog index 12ab5c5b7..81120070c 100644 --- a/gettext-tools/examples/ChangeLog +++ b/gettext-tools/examples/ChangeLog @@ -1,3 +1,19 @@ +2015-01-07 Daiki Ueno + + examples: Make hello-c-gnome3 translator friendly + Suggested by Benno Schulenberg in: + . + * hello-c-gnome3/hello.gschema.xml: Use "use-markup" property + instead of "sensitive", to clarify the meaning of the extracted + strings. + * hello-c-gnome3/hello.c (HelloApplicationWindow): Rename the + "label2" member to "label". + (update_content): New function. + (clicked_callback): Rename from quit_callback and call + update_content instead of quitting. All callers changed. + * hello-c-gnome3/hello.ui: Abolish the first label and put a + translatable text inside the button. + 2014-12-24 Daiki Ueno * gettext 0.19.4 released. diff --git a/gettext-tools/examples/hello-c-gnome3/hello.c b/gettext-tools/examples/hello-c-gnome3/hello.c index a642ac622..56fbf6a22 100644 --- a/gettext-tools/examples/hello-c-gnome3/hello.c +++ b/gettext-tools/examples/hello-c-gnome3/hello.c @@ -17,12 +17,6 @@ #define APPLICATION_ID "org.gnu.gettext.examples.hello" #define GSETTINGS_SCHEMA "org.gnu.gettext.examples.hello" -static void -quit_callback (GtkWidget *widget, void *data) -{ - g_application_quit (G_APPLICATION (data)); -} - /* Forward declaration of GObject types. */ #define HELLO_TYPE_APPLICATION_WINDOW (hello_application_window_get_type ()) @@ -48,9 +42,11 @@ typedef struct _HelloApplicationClass HelloApplicationClass; struct _HelloApplicationWindow { GtkApplicationWindow parent; - GtkWidget *label2; + GtkWidget *label; GtkWidget *button; GSettings *settings; + gsize label_id; + gchar *labels[3]; }; struct _HelloApplicationWindowClass @@ -62,20 +58,34 @@ G_DEFINE_TYPE (HelloApplicationWindow, hello_application_window, GTK_TYPE_APPLICATION_WINDOW); static void -hello_application_window_init (HelloApplicationWindow *window) +update_content (HelloApplicationWindow *window) { - char *label; + gtk_label_set_label (GTK_LABEL (window->label), + window->labels[window->label_id]); + window->label_id = (window->label_id + 1) % G_N_ELEMENTS (window->labels); +} +static void +hello_application_window_init (HelloApplicationWindow *window) +{ gtk_widget_init_template (GTK_WIDGET (window)); - label = g_strdup_printf (_("This program is running as process number %d."), - getpid ()); - gtk_label_set_label (GTK_LABEL (window->label2), label); - g_free (label); window->settings = g_settings_new (GSETTINGS_SCHEMA); - g_settings_bind (window->settings, "label-sensitive", - window->label2, "sensitive", + g_settings_bind (window->settings, "use-markup", + window->label, "use-markup", G_SETTINGS_BIND_DEFAULT); + + window->labels[0] + = g_strdup_printf (_("Hello world!\n" + "This program is running as " + "process number %d."), + getpid ()); + window->labels[1] + = g_strdup (_("This is another text")); + window->labels[2] + = g_strdup (_("This is yet another text")); + + update_content (window); } static void @@ -95,7 +105,7 @@ hello_application_window_class_init (HelloApplicationWindowClass *klass) gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (klass), UI_PATH); gtk_widget_class_bind_template_child (GTK_WIDGET_CLASS (klass), - HelloApplicationWindow, label2); + HelloApplicationWindow, label); gtk_widget_class_bind_template_child (GTK_WIDGET_CLASS (klass), HelloApplicationWindow, button); } @@ -127,6 +137,12 @@ hello_application_init (HelloApplication *application) { } +static void +clicked_callback (GtkWidget *widget, void *data) +{ + update_content (HELLO_APPLICATION_WINDOW (data)); +} + static void hello_application_activate (GApplication *application) { @@ -134,7 +150,7 @@ hello_application_activate (GApplication *application) window = hello_application_window_new (HELLO_APPLICATION (application)); g_signal_connect (window->button, "clicked", - G_CALLBACK (quit_callback), application); + G_CALLBACK (clicked_callback), window); gtk_window_present (GTK_WINDOW (window)); } diff --git a/gettext-tools/examples/hello-c-gnome3/hello.gschema.xml b/gettext-tools/examples/hello-c-gnome3/hello.gschema.xml index 40d2a90b5..d586b5a74 100644 --- a/gettext-tools/examples/hello-c-gnome3/hello.gschema.xml +++ b/gettext-tools/examples/hello-c-gnome3/hello.gschema.xml @@ -2,10 +2,10 @@ - + true - Set label sensitive - Whether to set the label sensitive. + Use XML markup + Whether to use XML markup in the text. diff --git a/gettext-tools/examples/hello-c-gnome3/hello.ui b/gettext-tools/examples/hello-c-gnome3/hello.ui index 9dc5c087b..a68f926fc 100644 --- a/gettext-tools/examples/hello-c-gnome3/hello.ui +++ b/gettext-tools/examples/hello-c-gnome3/hello.ui @@ -10,45 +10,34 @@ True vertical - + True - 0.0 + 0.5 0.5 0 0 + True - - True - Hello, world! - - - + + True + + + - + True - 0.0 - 0.5 - 0 - 0 - - True - - - - - - - True - - - True - gtk-ok - True - - - + + True + Update text + False + + + end + + +