+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.
#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 ())
struct _HelloApplicationWindow
{
GtkApplicationWindow parent;
- GtkWidget *label2;
+ GtkWidget *label;
GtkWidget *button;
GSettings *settings;
+ gsize label_id;
+ gchar *labels[3];
};
struct _HelloApplicationWindowClass
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
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);
}
{
}
+static void
+clicked_callback (GtkWidget *widget, void *data)
+{
+ update_content (HELLO_APPLICATION_WINDOW (data));
+}
+
static void
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));
}
<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>
<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>