[gnome-builder/wip/tingping/gstyle-translations] gstyle: Add support for translations



commit 6875c48e9fc80ae2069743767e25089ac5e722b7
Author: Patrick Griffis <tingping tingping se>
Date:   Thu Jul 21 20:14:34 2016 -0400

    gstyle: Add support for translations

 configure.ac                                       |    2 +-
 contrib/gstyle/Makefile.am                         |    5 ++
 contrib/gstyle/check-palette.sh                    |    2 +-
 contrib/gstyle/data/its/gstyle.its                 |    4 ++
 contrib/gstyle/data/its/gstyle.loc                 |    6 +++
 .../palette.xml => data/palettes/basic.gstyle.xml} |    2 +-
 contrib/gstyle/data/palettes/palette.rng           |    3 +
 contrib/gstyle/gstyle-palette.c                    |   48 +++++++++++++++++--
 .../basic.xml => tests/data/palette.gstyle.xml}    |    0
 contrib/gstyle/tests/test-gstyle-palette.c         |    2 +-
 .../data/{basic.xml => basic.gstyle.xml}           |   22 ++++-----
 .../color-picker/gb-color-picker-workbench-addin.c |    2 +-
 plugins/color-picker/gb-color-picker.gresource.xml |    2 +-
 po/Makevars                                        |    5 ++-
 po/POTFILES.in                                     |    4 +-
 po/POTFILES.skip                                   |    2 +
 16 files changed, 84 insertions(+), 27 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index ebe62c4..c896021 100644
--- a/configure.ac
+++ b/configure.ac
@@ -58,7 +58,7 @@ dnl ***********************************************************************
 GETTEXT_PACKAGE=AC_PACKAGE_TARNAME
 AC_DEFINE_UNQUOTED([GETTEXT_PACKAGE], ["$GETTEXT_PACKAGE"], [GETTEXT package name])
 AC_SUBST(GETTEXT_PACKAGE)
-AM_GNU_GETTEXT_VERSION([0.19.7])
+AM_GNU_GETTEXT_VERSION([0.19.8])
 AM_GNU_GETTEXT([external])
 
 
diff --git a/contrib/gstyle/Makefile.am b/contrib/gstyle/Makefile.am
index c7a8f5d..b8f6903 100644
--- a/contrib/gstyle/Makefile.am
+++ b/contrib/gstyle/Makefile.am
@@ -8,6 +8,11 @@ SUBDIRS = . tests
 pkglibdir = $(libdir)/gnome-builder
 pkglib_LTLIBRARIES = libgstyle-private.la
 
+#gettextitsdir = $(datadir)/gettext/its
+noinst_DATA =                    \
+       data/its/gstyle.its      \
+       data/its/gstyle.loc
+
 headersdir = $(includedir)/gnome-builder-@VERSION@/gstyle
 headers_DATA =                        \
        gstyle-animation.h            \
diff --git a/contrib/gstyle/check-palette.sh b/contrib/gstyle/check-palette.sh
index 72fcdba..befb4fb 100755
--- a/contrib/gstyle/check-palette.sh
+++ b/contrib/gstyle/check-palette.sh
@@ -9,7 +9,7 @@ if [ $1 ]; then
   files=$@
 else
   cd ./data/palettes
-  files=*.xml
+  files=*.gstyle.xml
 fi
 
 for file in $files; do
diff --git a/contrib/gstyle/data/its/gstyle.its b/contrib/gstyle/data/its/gstyle.its
new file mode 100644
index 0000000..405c1eb
--- /dev/null
+++ b/contrib/gstyle/data/its/gstyle.its
@@ -0,0 +1,4 @@
+<?xml version="1.0"?>
+<its:rules xmlns:its="http://www.w3.org/2005/11/its"; version="1.0">
+  <its:translateRule selector="//palette/@_name" translate="yes"/>
+</its:rules>
diff --git a/contrib/gstyle/data/its/gstyle.loc b/contrib/gstyle/data/its/gstyle.loc
new file mode 100644
index 0000000..f742495
--- /dev/null
+++ b/contrib/gstyle/data/its/gstyle.loc
@@ -0,0 +1,6 @@
+<?xml version="1.0"?>
+<locatingRules>
+  <locatingRule name="GStyle" pattern="*.gstyle.xml">
+    <documentRule localName="palette" target="gstyle.its"/>
+  </locatingRule>
+</locatingRules>
diff --git a/contrib/gstyle/tests/data/palette.xml b/contrib/gstyle/data/palettes/basic.gstyle.xml
similarity index 97%
rename from contrib/gstyle/tests/data/palette.xml
rename to contrib/gstyle/data/palettes/basic.gstyle.xml
index f62c42d..f5a33eb 100644
--- a/contrib/gstyle/tests/data/palette.xml
+++ b/contrib/gstyle/data/palettes/basic.gstyle.xml
@@ -17,7 +17,7 @@ You should have received a copy of the GNU General Public License
 along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 -->
-<palette id="basic" _name="Basic">
+<palette id="basic" name="Basic">
 
   <color name="color_hex6"           value="#808080"/>
   <color name="color_hex3"           value="#1aF"/>
diff --git a/contrib/gstyle/data/palettes/palette.rng b/contrib/gstyle/data/palettes/palette.rng
index 6046745..dc5c5e2 100644
--- a/contrib/gstyle/data/palettes/palette.rng
+++ b/contrib/gstyle/data/palettes/palette.rng
@@ -106,6 +106,9 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
       <attribute name="_name"/>
     </choice>
     <optional>
+      <attribute name="gettext-domain"/>
+    </optional>
+    <optional>
       <oneOrMore>
           <element name="color">
             <attribute name="name">
diff --git a/contrib/gstyle/gstyle-palette.c b/contrib/gstyle/gstyle-palette.c
index 0a927d0..4eecef3 100644
--- a/contrib/gstyle/gstyle-palette.c
+++ b/contrib/gstyle/gstyle-palette.c
@@ -38,6 +38,7 @@ struct _GstylePalette
   GHashTable *color_names;
   gchar      *id;
   gchar      *name;
+  gchar      *gettext_domain;
   GFile      *file;
 };
 
@@ -57,6 +58,7 @@ enum {
   PROP_FILE,
   PROP_COLORS,
   PROP_LEN,
+  PROP_DOMAIN,
   N_PROPS
 };
 
@@ -90,20 +92,27 @@ static GParamSpec *properties [N_PROPS];
 static gboolean
 gstyle_palette_xml_get_header (xmlTextReaderPtr   reader,
                                gchar            **id,
-                               gchar            **name)
+                               gchar            **name,
+                               gchar            **domain)
 {
   g_assert (reader != NULL);
   g_assert (id != NULL);
   g_assert (name != NULL);
+  g_assert (domain != NULL);
 
-  *id = *name = NULL;
+  *id = *name = *domain = NULL;
   if (xmlTextReaderRead(reader) == 1 &&
       xmlTextReaderNodeType (reader) == XML_READER_TYPE_ELEMENT &&
       !g_strcmp0 (XML_TO_CHAR (xmlTextReaderConstName (reader)), "palette") &&
       xmlTextReaderDepth (reader) == 0)
     {
       *id = strdup_and_xmlfree (xmlTextReaderGetAttribute (reader, CHAR_TO_XML ("id")));
-      *name = strdup_and_xmlfree (xmlTextReaderGetAttribute (reader, CHAR_TO_XML ("_name")));
+      *name = strdup_and_xmlfree (xmlTextReaderGetAttribute (reader, CHAR_TO_XML ("name")));
+      if (*name == NULL)
+        {
+          *name = strdup_and_xmlfree (xmlTextReaderGetAttribute (reader, CHAR_TO_XML ("_name")));
+          *domain = strdup_and_xmlfree (xmlTextReaderGetAttribute (reader, CHAR_TO_XML ("gettext-domain")));
+        }
       if (gstyle_str_empty0 (*id) || gstyle_utf8_is_spaces (*id))
         {
           g_warning ("Palette '%s'has an empty or NULL id\n", *name);
@@ -658,14 +667,16 @@ gstyle_palette_new_from_xml (GFile         *file,
       GstyleColor *color;
       g_autofree gchar *id = NULL;
       g_autofree gchar *name = NULL;
+      g_autofree gchar *domain = NULL;
 
       xmlTextReaderSetErrorHandler (reader, gstyle_palette_error_cb, NULL);
 
       if (xmlTextReaderRead(reader) &&
-          gstyle_palette_xml_get_header (reader, &id, &name))
+          gstyle_palette_xml_get_header (reader, &id, &name, &domain))
         {
           palette = g_object_new (GSTYLE_TYPE_PALETTE,
                                   "id", id,
+                                  "domain", domain,
                                   "name", name,
                                   "file", file,
                                   NULL);
@@ -873,7 +884,13 @@ gstyle_palette_save_to_xml (GstylePalette  *self,
   id = gstyle_palette_get_id (self);
   name = gstyle_palette_get_name (self);
   xmlNewProp (palette_node, CHAR_TO_XML ("id"), CHAR_TO_XML (id));
-  xmlNewProp (palette_node, CHAR_TO_XML ("_name"), CHAR_TO_XML (name));
+  if (self->gettext_domain)
+    {
+      xmlNewProp (palette_node, CHAR_TO_XML ("_name"), CHAR_TO_XML (name));
+      xmlNewProp (palette_node, CHAR_TO_XML ("gettext-domain"), CHAR_TO_XML (self->gettext_domain));
+    }
+  else
+    xmlNewProp (palette_node, CHAR_TO_XML ("name"), CHAR_TO_XML (name));
 
   n_colors = gstyle_palette_get_len (self);
   for (gint i = 0; i < n_colors; ++i)
@@ -922,6 +939,9 @@ gstyle_palette_set_name (GstylePalette *self,
 {
   g_return_if_fail (GSTYLE_IS_PALETTE (self));
 
+  if (self->gettext_domain)
+      name = g_dgettext (self->gettext_domain, name);
+
   if (g_strcmp0 (self->name, name) != 0)
     {
       g_free (self->name);
@@ -1039,6 +1059,7 @@ gstyle_palette_finalize (GObject *object)
 
   g_free (self->name);
   g_free (self->id);
+  g_free (self->gettext_domain);
   g_clear_object (&self->file);
 
   G_OBJECT_CLASS (gstyle_palette_parent_class)->finalize (object);
@@ -1062,6 +1083,10 @@ gstyle_palette_get_property (GObject    *object,
       g_value_set_string (value, self->name);
       break;
 
+    case PROP_DOMAIN:
+      g_value_set_string (value, self->gettext_domain);
+      break;
+
     case PROP_FILE:
       g_value_set_object (value, self->file);
       break;
@@ -1098,6 +1123,12 @@ gstyle_palette_set_property (GObject      *object,
       gstyle_palette_set_name (self, g_value_get_string (value));
       break;
 
+    case PROP_DOMAIN:
+      g_free (self->gettext_domain);
+      self->gettext_domain = g_value_dup_string (value);
+      bind_textdomain_codeset (self->gettext_domain, "UTF-8");
+      break;
+
     case PROP_FILE:
       file = g_value_get_object (value);
       self->file = file ? g_object_ref (file) : NULL;
@@ -1171,6 +1202,13 @@ gstyle_palette_class_init (GstylePaletteClass *klass)
                          NULL,
                          (G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_CONSTRUCT | 
G_PARAM_STATIC_STRINGS));
 
+  properties [PROP_DOMAIN] =
+    g_param_spec_string ("domain",
+                         "Gettext domain",
+                         "The Gettext domain the file uses.",
+                         NULL,
+                         (G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
+
   properties [PROP_FILE] =
     g_param_spec_object ("file",
                          "File",
diff --git a/contrib/gstyle/data/palettes/basic.xml b/contrib/gstyle/tests/data/palette.gstyle.xml
similarity index 100%
rename from contrib/gstyle/data/palettes/basic.xml
rename to contrib/gstyle/tests/data/palette.gstyle.xml
diff --git a/contrib/gstyle/tests/test-gstyle-palette.c b/contrib/gstyle/tests/test-gstyle-palette.c
index 2df7078..bdf93b5 100644
--- a/contrib/gstyle/tests/test-gstyle-palette.c
+++ b/contrib/gstyle/tests/test-gstyle-palette.c
@@ -55,7 +55,7 @@ test_palette (void)
   GstylePalette *palette;
 
   printf ("\n");
-  palette = load_palette ("palette.xml");
+  palette = load_palette ("palette.gstyle.xml");
   g_object_unref (palette);
 
   palette = load_palette ("palette.gpl");
diff --git a/plugins/color-picker/data/basic.xml b/plugins/color-picker/data/basic.gstyle.xml
similarity index 54%
rename from plugins/color-picker/data/basic.xml
rename to plugins/color-picker/data/basic.gstyle.xml
index f62c42d..a35302a 100644
--- a/plugins/color-picker/data/basic.xml
+++ b/plugins/color-picker/data/basic.gstyle.xml
@@ -17,16 +17,14 @@ You should have received a copy of the GNU General Public License
 along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 -->
-<palette id="basic" _name="Basic">
-
-  <color name="color_hex6"           value="#808080"/>
-  <color name="color_hex3"           value="#1aF"/>
-  <color name="color_rgb"            value="rgb(100, 200, 50)"/>
-  <color name="color_rgb_percent"    value="rgb(10%, 50%, 70%)"/>
-  <color name="color_rgba"           value="rgba(0, 10, 70, 1)"/>
-  <color name="color_rgba_percent"   value="rgba(10%, 50%, 40%, 0.5)"/>
-  <color name="color_hsl"            value="hsl(100, 100%, 50%)"/>
-  <color name="color_hsla"           value="hsla(400, 50%, 40%, 0.5)"/>
-  <color name="color_named"          value="aliceblue"/>
-
+<palette id="basic" _name="Basic" gettext-domain="gnome-builder">
+  <color name="color_hex6" value="#808080"/>
+  <color name="color_hex3" value="#1aF"/>
+  <color name="color_rgb" value="rgb(100, 200, 50)"/>
+  <color name="color_rgb_percent" value="rgb(10%, 50%, 70%)"/>
+  <color name="color_rgba" value="rgba(0, 10, 70, 1)"/>
+  <color name="color_rgba_percent" value="rgba(10%, 50%, 40%, 0.5)"/>
+  <color name="color_hsl" value="hsl(100, 100%, 50%)"/>
+  <color name="color_hsla" value="hsla(400, 50%, 40%, 0.5)"/>
+  <color name="color_named" value="aliceblue"/>
 </palette>
diff --git a/plugins/color-picker/gb-color-picker-workbench-addin.c 
b/plugins/color-picker/gb-color-picker-workbench-addin.c
index 89078a2..a9c4644 100644
--- a/plugins/color-picker/gb-color-picker-workbench-addin.c
+++ b/plugins/color-picker/gb-color-picker-workbench-addin.c
@@ -83,7 +83,7 @@ init_palettes (GbColorPickerWorkbenchAddin *self)
   g_assert (GB_IS_COLOR_PICKER_WORKBENCH_ADDIN (self));
 
   palette_widget = gstyle_color_panel_get_palette_widget (GSTYLE_COLOR_PANEL (self->color_panel));
-  add_palette (self, palette_widget, 
"resource:///org/gnome/builder/plugins/color-picker-plugin/data/basic.xml");
+  add_palette (self, palette_widget, 
"resource:///org/gnome/builder/plugins/color-picker-plugin/data/basic.gstyle.xml");
   palette = add_palette (self, palette_widget, 
"resource:///org/gnome/builder/plugins/color-picker-plugin/data/svg.gpl");
 
   gstyle_color_panel_show_palette (GSTYLE_COLOR_PANEL (self->color_panel), palette);
diff --git a/plugins/color-picker/gb-color-picker.gresource.xml 
b/plugins/color-picker/gb-color-picker.gresource.xml
index 4a50652..9a1c6bf 100644
--- a/plugins/color-picker/gb-color-picker.gresource.xml
+++ b/plugins/color-picker/gb-color-picker.gresource.xml
@@ -13,7 +13,7 @@
     <file>gtk/color-picker-palette-menu.ui</file>
     <file>gtk/menus.ui</file>
 
-    <file>data/basic.xml</file>
+    <file>data/basic.gstyle.xml</file>
     <file>data/svg.gpl</file>
 
     <file compressed="true" 
alias="icons/scalable/actions/builder-colorpicker-load-palette.svg">icons/palette/load-palette.svg</file>
diff --git a/po/Makevars b/po/Makevars
index dad02bf..336206c 100644
--- a/po/Makevars
+++ b/po/Makevars
@@ -7,8 +7,11 @@ DOMAIN = $(PACKAGE)
 subdir = po
 top_builddir = ..
 
+# This allows us using local its files
+XGETTEXT := env GETTEXTDATADIRS="$(top_builddir)/contrib/gstyle/data" $(XGETTEXT)
+
 # These options get passed to xgettext.
-XGETTEXT_OPTIONS =  --from-code=UTF-8 --keyword=_ --keyword=N_ --keyword=C_:1c,2 --keyword=NC_:1c,2 
--keyword=g_dngettext:2,3
+XGETTEXT_OPTIONS = --from-code=UTF-8 --keyword=_ --keyword=N_ --keyword=C_:1c,2 --keyword=NC_:1c,2 
--keyword=g_dngettext:2,3
 
 # This is the copyright holder that gets inserted into the header of the
 # $(DOMAIN).pot file.  Set this to the copyright holder of the surrounding
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 60299fe..ef16586 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -4,14 +4,12 @@ contrib/egg/egg-animation.c
 contrib/egg/egg-date-time.c
 contrib/egg/egg-file-chooser-entry.c
 contrib/egg/egg-search-bar.c
-contrib/gstyle/data/palettes/basic.xml
 contrib/gstyle/gstyle-color-panel.c
 contrib/gstyle/gstyle-color-plane.c
 contrib/gstyle/gstyle-color-widget-actions.c
 contrib/gstyle/gstyle-palette.c
 contrib/gstyle/gstyle-palette-widget.c
 contrib/gstyle/tests/data/gstyle-color-editor.ui
-contrib/gstyle/tests/data/palette.xml
 contrib/gstyle/ui/gstyle-color-panel.ui
 contrib/gstyle/ui/gstyle-color-widget.ui
 contrib/gstyle/ui/gstyle-rename-popover.ui
@@ -111,7 +109,7 @@ plugins/clang/ide-clang-preferences-addin.c
 plugins/clang/ide-clang-service.c
 plugins/clang/ide-clang-symbol-node.c
 plugins/clang/ide-clang-translation-unit.c
-plugins/color-picker/data/basic.xml
+plugins/color-picker/data/basic.gstyle.xml
 plugins/color-picker/gb-color-picker-prefs.c
 plugins/color-picker/gb-color-picker-prefs-palette-row.c
 plugins/color-picker/gb-color-picker-workbench-addin.c
diff --git a/po/POTFILES.skip b/po/POTFILES.skip
index d1de359..ece41d0 100644
--- a/po/POTFILES.skip
+++ b/po/POTFILES.skip
@@ -1,5 +1,7 @@
 # List of source files that should *not* be translated.
 # Please keep this file sorted alphabetically.
+contrib/gstyle/data/palettes/basic.gstyle.xml
+contrib/gstyle/tests/data/palette.gstyle.xml
 contrib/tmpl/tmpl-expr-parser.c
 plugins/vala-pack/ide-vala-preferences-addin.c
 sub/plugins/vala-pack/ide-vala-preferences-addin.c


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]