[caribou] make_schema: don't translate strings in schema files



commit 2f03ff63b8f429a5bb368ce55122961e1271a434
Author: Daiki Ueno <ueno unixuser org>
Date:   Tue Oct 16 11:51:09 2012 +0900

    make_schema: don't translate strings in schema files
    
    Prevent summary and description fields in gschema files from being
    translated.  Also embed gettext-domain in schemas.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=686200

 data/Makefile.am     |    6 ++++--
 tools/make_schema.py |   32 +++++++++++++++++++++++---------
 2 files changed, 27 insertions(+), 11 deletions(-)
---
diff --git a/data/Makefile.am b/data/Makefile.am
index 02b725a..b63533e 100644
--- a/data/Makefile.am
+++ b/data/Makefile.am
@@ -27,10 +27,12 @@ org.gnome.Caribou.Antler.service: org.gnome.Caribou.Antler.service.in
 EXTRA_DIST = $(desktop_in_files) $(autostart_in_files) $(servicefile_in_files)
 
 org.gnome.caribou.gschema.xml.in: $(top_srcdir)/caribou/settings/caribou_settings.py
-	$(top_srcdir)/tools/make_schema.py caribou.settings.CaribouSettings
+	$(AM_V_GEN)$(top_srcdir)/tools/make_schema.py -d "$(GETTEXT_PACKAGE)" \
+		-o $@ caribou.settings.CaribouSettings
 
 org.gnome.antler.gschema.xml.in: $(top_srcdir)/caribou/antler/antler_settings.py
-	$(top_srcdir)/tools/make_schema.py caribou.antler.AntlerSettings
+	$(AM_V_GEN)$(top_srcdir)/tools/make_schema.py -d "$(GETTEXT_PACKAGE)" \
+		-o $@ caribou.antler.AntlerSettings
 
 CLEANFILES = $(desktop_DATA) \
 	$(autostart_DATA) \
diff --git a/tools/make_schema.py b/tools/make_schema.py
index 7237ac4..f8386dc 100755
--- a/tools/make_schema.py
+++ b/tools/make_schema.py
@@ -9,18 +9,20 @@ sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
 from caribou.settings import caribou_settings
 
 class SchemasMaker:
-    def __init__(self, settings):
+    def __init__(self, settings, domain):
         self.settings = settings
+        self.domain = domain
 
-    def create_schemas(self):
+    def create_schemas(self, output):
         doc = xml.dom.minidom.Document()
         schemafile =  doc.createElement('schemalist')
         schema = doc.createElement('schema')
         schema.setAttribute("id", self.settings.schema_id)
+        schema.setAttribute("gettext-domain", self.domain)
         schemafile.appendChild(schema)
         self._create_schema(self.settings, doc, schema)
 
-        fp = open("%s.gschema.xml.in" % self.settings.schema_id, 'w')
+        fp = open(output, 'w')
         self._pretty_xml(fp, schemafile)
         fp.close()
 
@@ -77,15 +79,27 @@ class SchemasMaker:
 
 if __name__ == "__main__":
     from caribou.settings import AllSettings
+    from locale import setlocale, LC_ALL
+    import argparse
 
-    if (len(sys.argv) != 2):
-        print "usage: %s <schema id>" % sys.argv[0]
-        sys.exit(1)
+    parser = argparse.ArgumentParser(description='make_schema')
 
-    modulename, settings_obj = sys.argv[-1].rsplit('.', 1)
+    parser.add_argument('settings_object', type=str,
+                        help='Settings object')
+    parser.add_argument('-o', '--output', type=str, required=True,
+                        help='Output file name')
+    parser.add_argument('-d', '--domain', type=str, default='caribou',
+                        help='Translation domain')
+
+    args = parser.parse_args()
+
+    # prevent _summary and _description from being translated
+    setlocale(LC_ALL, "C")
+
+    modulename, settings_obj = args.settings_object.rsplit('.', 1)
 
     module = __import__(modulename, locals(), globals(), [settings_obj])
     settings = getattr(module, settings_obj)
 
-    maker = SchemasMaker(settings)
-    maker.create_schemas()
+    maker = SchemasMaker(settings, args.domain)
+    maker.create_schemas(args.output)



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