From b795cc152c01e6ca937954c7b99f71e3a324b6ff Mon Sep 17 00:00:00 2001 From: David Schulz Date: Fri, 19 Jan 2018 11:16:19 +0100 Subject: [PATCH] Editor: make additional snippet info translatable Additional snippet information is displayed in the options and when completing snippets to distinguish between multiple snippets with the same trigger. This information is extracted from xml files. Translate these strings like the information for external tools. Task-number: QTCREATORBUG-5912 Change-Id: I90a22d687a99339b8f30c0de3b04b379085b6bd5 Reviewed-by: Robert Loehning Reviewed-by: Oswald Buddenhagen --- share/qtcreator/translations/extract-snippets.xq | 9 +++++++++ share/qtcreator/translations/translations.pro | 9 +++++++-- .../texteditor/snippets/snippetscollection.cpp | 12 +++++++++++- 3 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 share/qtcreator/translations/extract-snippets.xq diff --git a/share/qtcreator/translations/extract-snippets.xq b/share/qtcreator/translations/extract-snippets.xq new file mode 100644 index 00000000000..0b7e52d4766 --- /dev/null +++ b/share/qtcreator/translations/extract-snippets.xq @@ -0,0 +1,9 @@ +let $prefix := string("QT_TRANSLATE_NOOP3("TextEditor::Internal::Snippets", "") +let $midfix := string("", "") +let $suffix := concat("")", codepoints-to-string(10)) +for $file in tokenize($files, string("\|")) + for $snippet in (doc($file)/*/snippet) + let $group := fn:concat(string("group:'"), data($snippet/@group), string("' ")) + let $trigger := fn:concat(string("trigger:'"), data($snippet/@trigger), string("'")) + where ($snippet/@complement) + return fn:concat($prefix, data($snippet/@complement), $midfix, $group, $trigger, $suffix) diff --git a/share/qtcreator/translations/translations.pro b/share/qtcreator/translations/translations.pro index 5f752f28551..9a3e296dda3 100644 --- a/share/qtcreator/translations/translations.pro +++ b/share/qtcreator/translations/translations.pro @@ -27,6 +27,7 @@ JSONWIZARD_TR_H = $$OUT_PWD/jsonwizard_tr.h QMLWIZARD_TR_H = $$OUT_PWD/qmlwizard_tr.h QTQUICKWIZARD_TR_H = $$OUT_PWD/qtquickwizard_tr.h EXTERNALTOOLS_TR_H = $$OUT_PWD/externaltools_tr.h +SNIPPETS_TR_H = $$OUT_PWD/snippets_tr.h win32: \ PREFIX = "file:///" @@ -48,12 +49,16 @@ QTQUICKWIZARD_FILES = \"$$join(QTQUICKWIZARD_FILES, "|$$PREFIX", "$$PREFIX")\" for(file, $$list($$files($$IDE_SOURCE_TREE/src/share/qtcreator/externaltools/*))):EXTERNALTOOLS_FILES += $$files($$file) EXTERNALTOOLS_FILES = \"$$join(EXTERNALTOOLS_FILES, "|$$PREFIX", "$$PREFIX")\" +for(file, $$list($$files($$IDE_SOURCE_TREE/share/qtcreator/snippets/*))):SNIPPETS_FILES += $$files($$file) +SNIPPETS_FILES = \"$$join(SNIPPETS_FILES, "|$$PREFIX", "$$PREFIX")\" + extract.commands += \ $$XMLPATTERNS -output $$MIME_TR_H -param files=$$MIMETYPES_FILES $$PWD/extract-mimetypes.xq $$escape_expand(\\n\\t) \ $$XMLPATTERNS -output $$CUSTOMWIZARD_TR_H -param files=$$CUSTOMWIZARD_FILES $$PWD/extract-customwizards.xq $$escape_expand(\\n\\t) \ $$XMLPATTERNS -output $$QMLWIZARD_TR_H -param files=$$QMLWIZARD_FILES $$PWD/extract-qmlwizards.xq $$escape_expand(\\n\\t) \ $$XMLPATTERNS -output $$QTQUICKWIZARD_TR_H -param files=$$QTQUICKWIZARD_FILES $$PWD/extract-qtquickwizards.xq $$escape_expand(\\n\\t) \ $$XMLPATTERNS -output $$EXTERNALTOOLS_TR_H -param files=$$EXTERNALTOOLS_FILES $$PWD/extract-externaltools.xq $$escape_expand(\\n\\t) \ + $$XMLPATTERNS -output $$SNIPPETS_TR_H -param files=$$SNIPPETS_FILES $$PWD/extract-snippets.xq $$escape_expand(\\n\\t) \ $(QMAKE) -o Makefile.jsonwizard JSONWIZARD_TR_H=\"$$JSONWIZARD_TR_H\" TOP_LEVEL=\"$$IDE_SOURCE_TREE/share/qtcreator/templates/wizards\" $$PWD/jsonwizard_tr.pro QMAKE_EXTRA_TARGETS += extract @@ -77,12 +82,12 @@ files = $$files($$PWD/*_??.ts) $$PWD/qtcreator_untranslated.ts for(file, files) { lang = $$replace(file, .*_([^/]*)\\.ts, \\1) v = ts-$${lang}.commands - $$v = cd $$wd && $$LUPDATE $$include_options $$sources $$MIME_TR_H $$CUSTOMWIZARD_TR_H $$JSONWIZARD_TR_H $$QMLWIZARD_TR_H $$QTQUICKWIZARD_TR_H $$EXTERNALTOOLS_TR_H -ts $$file + $$v = cd $$wd && $$LUPDATE $$include_options $$sources $$MIME_TR_H $$CUSTOMWIZARD_TR_H $$JSONWIZARD_TR_H $$QMLWIZARD_TR_H $$QTQUICKWIZARD_TR_H $$EXTERNALTOOLS_TR_H $$SNIPPETS_TR_H -ts $$file v = ts-$${lang}.depends $$v = extract QMAKE_EXTRA_TARGETS += ts-$$lang } -ts-all.commands = cd $$wd && $$LUPDATE $$include_options $$sources $$MIME_TR_H $$CUSTOMWIZARD_TR_H $$JSONWIZARD_TR_H $$QMLWIZARD_TR_H $$QTQUICKWIZARD_TR_H $$EXTERNALTOOLS_TR_H -ts $$files +ts-all.commands = cd $$wd && $$LUPDATE $$include_options $$sources $$MIME_TR_H $$CUSTOMWIZARD_TR_H $$JSONWIZARD_TR_H $$QMLWIZARD_TR_H $$QTQUICKWIZARD_TR_H $$EXTERNALTOOLS_TR_H SNIPPETS_TR_H -ts $$files ts-all.depends = extract QMAKE_EXTRA_TARGETS += ts-all diff --git a/src/plugins/texteditor/snippets/snippetscollection.cpp b/src/plugins/texteditor/snippets/snippetscollection.cpp index 20c9615d5a6..2aeed388555 100644 --- a/src/plugins/texteditor/snippets/snippetscollection.cpp +++ b/src/plugins/texteditor/snippets/snippetscollection.cpp @@ -44,6 +44,13 @@ using namespace TextEditor; using namespace Internal; +/* TRANSLATOR TextEditor::Internal::Snippets + + Snippets are text fragments that can be inserted into an editor via the usual completion + mechanics using a trigger text. The translated text (trigger variant) is used to + disambiguate between snippets with the same trigger. +*/ + namespace { static bool snippetComp(const Snippet &a, const Snippet &b) @@ -359,7 +366,10 @@ QList SnippetsCollection::readXML(const QString &fileName, const QStrin if (isGroupKnown(groupId) && (snippetId.isEmpty() || snippetId == id)) { Snippet snippet(groupId, id); snippet.setTrigger(atts.value(kTrigger).toString()); - snippet.setComplement(atts.value(kComplement).toString()); + snippet.setComplement(QCoreApplication::translate( + "TextEditor::Internal::Snippets", + atts.value(kComplement).toString().toLatin1(), + atts.value(kId).toString().toLatin1())); snippet.setIsRemoved(toBool(atts.value(kRemoved).toString())); snippet.setIsModified(toBool(atts.value(kModified).toString()));