fileUtils: Add helper for loading D-Bus XML from resource

Commit dbf993300a moved all inline D-Bus interface descriptions to template
strings so we can stop escaping line breaks.

Unfortunately that unveiled a grave bug in xgettext, which currently cannot
handle files that contain both backtick and slash characters - as a result,
translations from affected files have started to disappear as translators
run xgettext/msgmerge.

Instead of reverting the change and getting the crusty escaping back, we
will take this as an opportunity to stop inlining the XML altogether and
load it from a resource instead.

To facilitate that, add a small helper method that loads a D-Bus interface
description from a dedicated resource bundle.

https://gitlab.gnome.org/GNOME/gnome-shell/issues/537
This commit is contained in:
Florian Müllner
2018-09-06 02:04:47 +02:00
committed by Jonas Ådahl
parent 150a640c66
commit f42d9df3e0
4 changed files with 49 additions and 16 deletions

View File

@ -3,6 +3,7 @@
const Gio = imports.gi.Gio;
const GLib = imports.gi.GLib;
const Lang = imports.lang;
const Config = imports.misc.config;
const Params = imports.misc.params;
function collectFromDatadirs(subdir, includeUserDir, processFile) {
@ -70,3 +71,29 @@ function recursivelyMoveDir(srcDir, destDir) {
recursivelyMoveDir(srcChild, destChild);
}
}
let _ifaceResource = null;
function loadInterfaceXML(iface) {
if (!_ifaceResource) {
// don't use global.datadir so the method is usable from tools
let path = Config.PKGDATADIR + '/gnome-shell-dbus-interfaces.gresource';
_ifaceResource = Gio.Resource.load(path);
_ifaceResource._register();
}
let xml = null;
let uri = 'resource:///org/gnome/shell/dbus-interfaces/' + iface + '.xml';
let f = Gio.File.new_for_uri(uri);
try {
let [ok, bytes] = f.load_contents(null);
if (bytes instanceof Uint8Array)
xml = imports.byteArray.toString(bytes)
else
xml = bytes;
} catch (e) {
log('Failed to load D-Bus interface ' + iface);
}
return xml;
}