]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
examples: Make hello-c-gnome3 translator friendly
authorDaiki Ueno <ueno@gnu.org>
Thu, 8 Jan 2015 02:09:14 +0000 (11:09 +0900)
committerDaiki Ueno <ueno@gnu.org>
Thu, 8 Jan 2015 02:25:32 +0000 (11:25 +0900)
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.

gettext-tools/examples/ChangeLog
gettext-tools/examples/hello-c-gnome3/hello.c
gettext-tools/examples/hello-c-gnome3/hello.gschema.xml
gettext-tools/examples/hello-c-gnome3/hello.ui

index 12ab5c5b7b4d7ab6498f3ef215baf5cb2b258ca5..81120070c6b495fdf335a4ffe51e3f70cd5b2775 100644 (file)
@@ -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.
index a642ac622c31d2e9b7c92024efd89b511082815c..56fbf6a22aa3111f226305c11a0285a8a1626127 100644 (file)
 #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);
 }
@@ -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));
 }
 
index 40d2a90b5cf12f5bf9feccd63146820d9433cebb..d586b5a741e42f64040dbd4d1efcf67115a88665 100644 (file)
@@ -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>
index 9dc5c087bde4bb3492522fe239bbc6d6c3153ca8..a68f926fcffd9c1941a28f89e6b11293203faa29 100644 (file)
         <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>