[open-ils-commits] r10563 - trunk/build/i18n/scripts
svn at svn.open-ils.org
svn at svn.open-ils.org
Tue Sep 9 00:29:28 EDT 2008
Author: dbs
Date: 2008-09-09 00:29:26 -0400 (Tue, 09 Sep 2008)
New Revision: 10563
Added:
trunk/build/i18n/scripts/merge_ils_events.py
Log:
Provide a mechanism for merging localized ils_events.xml into master ils_events.xml
Added: trunk/build/i18n/scripts/merge_ils_events.py
===================================================================
--- trunk/build/i18n/scripts/merge_ils_events.py (rev 0)
+++ trunk/build/i18n/scripts/merge_ils_events.py 2008-09-09 04:29:26 UTC (rev 10563)
@@ -0,0 +1,74 @@
+#!/usr/bin/env python
+import xml.dom.minidom
+import optparse
+
+def merge_events(master, localization):
+ """
+ Merge two event definition files
+ """
+
+ master_xml = xml.dom.minidom.parse(master)
+ l10n_xml = xml.dom.minidom.parse(localization)
+ impl = xml.dom.minidom.getDOMImplementation()
+
+ merged = impl.createDocument(None, 'ils_events', None)
+
+ # Add notes
+ notes = master_xml.getElementsByTagName('notes')[0]
+ merged.documentElement.appendChild(notes)
+
+ events = master_xml.getElementsByTagName('event')
+ for event in events:
+ merged.documentElement.appendChild(event)
+ event.appendChild(get_l10n_event_desc(l10n_xml, event.getAttribute('code')))
+
+ return merged
+
+def get_l10n_event_desc(l10n_xml, code):
+ """
+ Gets a localized event description
+ """
+
+ desc_nodes = ''
+
+ events = l10n_xml.getElementsByTagName('event')
+ for event in events:
+ if event.getAttribute('code') == code:
+ for node in event.childNodes:
+ if node.nodeName == 'desc':
+ return node
+ else:
+ continue
+
+def main():
+ """
+ Determine what action to take
+ """
+ opts = optparse.OptionParser()
+ opts.add_option('-m', '--master', action='store', \
+ help='Master ils_events.xml file into which we are merging our additional localized strings', \
+ metavar='FILE')
+ opts.add_option('-l', '--localization', action='store', \
+ help='Localized ils_events.xml file', \
+ metavar='FILE')
+ opts.add_option('-o', '--output', dest='outfile', \
+ help='Write output to FILE (defaults to STDOUT)', metavar='FILE')
+ (options, args) = opts.parse_args()
+
+ if not options.master:
+ opts.error('Must specify the master ils_events file (-m option)')
+ elif not options.localization:
+ opts.error('Must specify the localized ils_events file to merge (-l option)')
+ else:
+ merged = merge_events(options.master, options.localization)
+
+ if options.outfile:
+ outfile = open(options.outfile, 'w')
+ outfile.write(merged.toprettyxml(encoding='utf-8'))
+ else:
+ print merged.toprettyxml(encoding='utf-8')
+
+if __name__ == '__main__':
+ main()
+
+# vim:et:ts=4:sw=4:
More information about the open-ils-commits
mailing list