From 2c414f21a6acefc0a0aa99e4641b05a034fd1dcb Mon Sep 17 00:00:00 2001
From: Sergey Belyashov <Sergey.Belyashov@gmail.com>
Date: Thu, 16 Jul 2009 09:28:56 +0200
Subject: [PATCH] Added possibility to translate file types in open/save
 dialogs.

Merge-request: 900
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@nokia.com>
---
 .../translations/extract-mimetypes.xq.in         |  6 ++++++
 share/qtcreator/translations/translations.pro    | 16 ++++++++++++++--
 src/plugins/coreplugin/mimedatabase.cpp          |  2 +-
 3 files changed, 21 insertions(+), 3 deletions(-)
 create mode 100644 share/qtcreator/translations/extract-mimetypes.xq.in

diff --git a/share/qtcreator/translations/extract-mimetypes.xq.in b/share/qtcreator/translations/extract-mimetypes.xq.in
new file mode 100644
index 00000000000..8a4bb835f7d
--- /dev/null
+++ b/share/qtcreator/translations/extract-mimetypes.xq.in
@@ -0,0 +1,6 @@
+let $files := ( $$MIMETYPES_FILES )
+let $prefix := string(\"QT_TRANSLATE_NOOP(&quot;MimeType&quot;, &quot;\")
+let $suffix := concat(\"&quot;)\", codepoints-to-string(10))
+for $file in $files
+    for $comment in doc($file)/*:mime-info/*:mime-type/*:comment
+        return fn:concat($prefix, data($comment), $suffix)
diff --git a/share/qtcreator/translations/translations.pro b/share/qtcreator/translations/translations.pro
index f56a2324e21..844d427b98e 100644
--- a/share/qtcreator/translations/translations.pro
+++ b/share/qtcreator/translations/translations.pro
@@ -8,13 +8,25 @@ defineReplace(prependAll) {
     return($$result)
 }
 
+XMLPATTERNS = $$targetPath($$[QT_INSTALL_BINS]/xmlpatterns)
 LUPDATE = $$targetPath($$[QT_INSTALL_BINS]/lupdate) -locations relative -no-ui-lines
 LRELEASE = $$targetPath($$[QT_INSTALL_BINS]/lrelease)
 
 TRANSLATIONS = $$prependAll(LANGUAGES, $$PWD/qtcreator_,.ts)
 
-contains(QT_VERSION, ^4\.[0-5]\..*):ts.commands = @echo This Qt version is too old for the ts target. Need Qt 4.6+.
-else:ts.commands = (cd $$IDE_SOURCE_TREE && $$LUPDATE src -ts $$TRANSLATIONS)
+MIME_TR_H = $$IDE_DATA_PATH/translations/mime_tr.h
+
+contains(QT_VERSION, ^4\.[0-5]\..*) {
+    ts.commands = @echo This Qt version is too old for the ts target. Need Qt 4.6+.
+} else {
+    for(dir, $$list($$files($$IDE_SOURCE_TREE/src/plugins/*))):MIMETYPES_FILES += $$files($$dir/*.mimetypes.xml)
+    MIMETYPES_FILES = \"$$join(MIMETYPES_FILES, \", \")\"
+    QMAKE_SUBSTITUTES += extract-mimetypes.xq.in
+    ts.commands += \
+        $$XMLPATTERNS -output $$MIME_TR_H $$PWD/extract-mimetypes.xq && \
+        (cd $$IDE_SOURCE_TREE && $$LUPDATE src $$MIME_TR_H -ts $$TRANSLATIONS) && \
+        $$QMAKE_DEL_FILE $$MIME_TR_H
+}
 QMAKE_EXTRA_TARGETS += ts
 
 TEMPLATE = app
diff --git a/src/plugins/coreplugin/mimedatabase.cpp b/src/plugins/coreplugin/mimedatabase.cpp
index e18edea7337..93652263516 100644
--- a/src/plugins/coreplugin/mimedatabase.cpp
+++ b/src/plugins/coreplugin/mimedatabase.cpp
@@ -717,7 +717,7 @@ bool BaseMimeTypeParser::parse(QIODevice *dev, const QString &fileName, QString
             case ParseComment: {
                 // comments have locale attributes. We want the default, English one
                 QString locale = reader.attributes().value(QLatin1String(localeAttributeC)).toString();
-                const QString comment = reader.readElementText();
+                const QString comment = QCoreApplication::translate("MimeType", reader.readElementText().toAscii());
                 if (locale.isEmpty()) {
                     data.comment = comment;
                 } else {
-- 
GitLab