Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mumble-voip/mumble.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMikkel Krautz <mikkel@krautz.dk>2015-10-17 22:47:01 +0300
committerMikkel Krautz <mikkel@krautz.dk>2015-10-17 22:47:42 +0300
commit311f6f7e86fad11b13ccfaa82d663c369ace16cb (patch)
tree888cff94e793ae8d68720dedd20cca9bf84544c6 /scripts/generate-mumble_qt-qrc.py
parent15f47f4f858ea0a95145e12f43f1c3f8e0d326ef (diff)
Auto-generate qrc file for embedded Qt translations when running qmake.
This change removes our qmake-based Qt translation embedding. That system uses mumble_qt.qrc resource file with hardcoded filenames for Qt translations, and some logic implemented in qmake that copies Qt translations into the Mumble source tree such that the paths in the mumble_qt.qrc file match. The new system introduces a simple Python script that takes an output filename for the .qrc file the tool will write, along with a set of directories containing Qt translations. The tool will generate a Qt resource file containing references to all the translation files found in the specified directories. However, the tool takes care to only include language files once. In typical use, the first directory parameter passed to the tool is the QT_INSTALL_TRANSLATIONS directory, which is where Qt stores its own translation files. The second directory is Mumble's fallback directory. The tool then goes through all files in the first directory, and notes down which languages have been processed. Multiple files for a single langauge can be included from the a directory (qt_help_da.qm, and qtbase_da.qm), but once a language has been added from one directory, it will not be added if found in the next one in line. We use this to include a set of 'fallback' translations for versions of Qt that do not include them. This also allows this new style of Qt translation embedding to be forward compatible with newer versions of Qt that add new translations. Once Qt includes a translation that we have in our fallback directory, the Qt translation is used instead.
Diffstat (limited to 'scripts/generate-mumble_qt-qrc.py')
-rwxr-xr-xscripts/generate-mumble_qt-qrc.py87
1 files changed, 87 insertions, 0 deletions
diff --git a/scripts/generate-mumble_qt-qrc.py b/scripts/generate-mumble_qt-qrc.py
new file mode 100755
index 000000000..168c98c8a
--- /dev/null
+++ b/scripts/generate-mumble_qt-qrc.py
@@ -0,0 +1,87 @@
+#!/usr/bin/env python
+#
+# Copyright (C) 2015 Mikkel Krautz <mikkel@krautz.dk>
+#
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# - Redistributions of source code must retain the above copyright notice,
+# this list of conditions and the following disclaimer.
+# - Redistributions in binary form must reproduce the above copyright notice,
+# this list of conditions and the following disclaimer in the documentation
+# and/or other materials provided with the distribution.
+# - Neither the name of the Mumble Developers nor the names of its
+# contributors may be used to endorse or promote products derived from this
+# software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
+# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+from __future__ import (unicode_literals, print_function, division)
+
+import os
+import platform
+import sys
+
+allowed_prefixes = ('qt', 'qtbase')
+
+def dirToQrc(of, dirName, alreadyProcessedLangs):
+ processedLangs = []
+ absDirName = os.path.abspath(dirName)
+ fns = os.listdir(dirName)
+ for fn in fns:
+ fnRoot, fnExt = os.path.splitext(fn)
+ if fnExt.lower() != '.qm':
+ continue
+ lastUnderscoreIdx = fnRoot.rfind('_')
+ if lastUnderscoreIdx == -1:
+ continue
+ prefix = fnRoot[:lastUnderscoreIdx]
+ lang = fnRoot[lastUnderscoreIdx+1:]
+ # Handle en_US-style locale names
+ if lang.upper() == lang:
+ nextToLastUnderscoreIdx = prefix.rfind('_')
+ prefix = fnRoot[:nextToLastUnderscoreIdx]
+ lang = fnRoot[nextToLastUnderscoreIdx+1:]
+ if lang in alreadyProcessedLangs:
+ continue
+ if not prefix in allowed_prefixes:
+ continue
+ absFn = os.path.join(absDirName, fn)
+ if platform.system() == 'Windows':
+ absFn = absFn.replace('\\', '/')
+ of.write(' <file alias="{0}">{1}</file>\n'.format(fn, absFn))
+ processedLangs.append(lang)
+ return processedLangs
+
+def main():
+ # python generate-mumble_qt-qrc.py <output-fn> [inputs...]
+ output = sys.argv[1]
+ inputs = sys.argv[2:]
+
+ of = open(output, 'w')
+ of.write('<!DOCTYPE RCC><RCC version="1.0">\n')
+ of.write('<qresource>\n')
+ processedLangs = []
+ for dirName in inputs:
+ newlyProcssedLangs = dirToQrc(of, dirName, processedLangs)
+ processedLangs.extend(newlyProcssedLangs)
+ of.write('</qresource>\n')
+ of.write('</RCC>\n')
+ of.close()
+
+if __name__ == '__main__':
+ main()