summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaiki Ueno <ueno@gnu.org>2015-01-08 11:09:14 +0900
committerDaiki Ueno <ueno@gnu.org>2015-01-08 11:25:32 +0900
commitabcef7b39a2b3e5dd2c963339ef00180dbd67677 (patch)
treeec487a8c9f9cd92792159182d83c6d060d4577b9
parent824a663ae260921d3f3b2e71a4d85c4a6a5e05a1 (diff)
downloadgettext-abcef7b39a2b3e5dd2c963339ef00180dbd67677.tar.gz
examples: Make hello-c-gnome3 translator friendly
Suggested by Benno Schulenberg in: <https://lists.gnu.org/archive/html/bug-gettext/2015-01/msg00003.html>. * 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.
-rw-r--r--gettext-tools/examples/ChangeLog16
-rw-r--r--gettext-tools/examples/hello-c-gnome3/hello.c50
-rw-r--r--gettext-tools/examples/hello-c-gnome3/hello.gschema.xml6
-rw-r--r--gettext-tools/examples/hello-c-gnome3/hello.ui49
4 files changed, 71 insertions, 50 deletions
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 <ueno@gnu.org>
+
+ examples: Make hello-c-gnome3 translator friendly
+ Suggested by Benno Schulenberg in:
+ <https://lists.gnu.org/archive/html/bug-gettext/2015-01/msg00003.html>.
+ * 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 <ueno@gnu.org>
* 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 (_("<big>Hello world!</big>\n"
+ "This program is running as "
+ "process number <b>%d</b>."),
+ getpid ());
+ window->labels[1]
+ = g_strdup (_("<big><u>This is another text</u></big>"));
+ window->labels[2]
+ = g_strdup (_("<big><i>This is yet another text</i></big>"));
+
+ 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);
}
@@ -128,13 +138,19 @@ 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)
{
HelloApplicationWindow *window;
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 @@
<schemalist>
<schema path="/org/gnu/gettext/examples/hello/"
id="org.gnu.gettext.examples.hello">
- <key name="label-sensitive" type="b">
+ <key name="use-markup" type="b">
<default>true</default>
- <summary>Set label sensitive</summary>
- <description>Whether to set the label sensitive.</description>
+ <summary>Use XML markup</summary>
+ <description>Whether to use XML markup in the text.</description>
</key>
</schema>
</schemalist>
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 @@
<property name="visible">True</property>
<property name="orientation">vertical</property>
<child>
- <object class="GtkAlignment" id="label1aligned">
+ <object class="GtkAlignment" id="alignment">
<property name="visible">True</property>
- <property name="xalign">0.0</property>
+ <property name="xalign">0.5</property>
<property name="yalign">0.5</property>
<property name="xscale">0</property>
<property name="yscale">0</property>
+ <property name="vexpand">True</property>
<child>
- <object class="GtkLabel" id="label1">
- <property name="visible">True</property>
- <property name="label" translatable="yes">Hello, world!</property>
- </object>
- </child>
- </object>
+ <object class="GtkLabel" id="label">
+ <property name="visible">True</property>
+ </object>
+ </child>
+ </object>
</child>
<child>
- <object class="GtkAlignment" id="label2aligned">
+ <object class="GtkHButtonBox" id="buttonbar">
<property name="visible">True</property>
- <property name="xalign">0.0</property>
- <property name="yalign">0.5</property>
- <property name="xscale">0</property>
- <property name="yscale">0</property>
<child>
- <object class="GtkLabel" id="label2">
- <property name="visible">True</property>
- </object>
- </child>
- </object>
- </child>
- <child>
- <object class="GtkHButtonBox" id="buttonbar">
- <property name="visible">True</property>
- <child>
- <object class="GtkButton" id="button">
- <property name="visible">True</property>
- <property name="label">gtk-ok</property>
- <property name="use_stock">True</property>
- </object>
- </child>
- </object>
+ <object class="GtkButton" id="button">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">Update text</property>
+ <property name="use_stock">False</property>
+ </object>
+ <packing>
+ <property name="pack-type">end</property>
+ </packing>
+ </child>
+ </object>
</child>
</object>
</child>