summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLucie Gérard <lucie.gerard@qt.io>2023-12-15 18:38:45 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2024-01-17 18:07:37 +0000
commite6e5d36bdb665b5868256aad976d798114025997 (patch)
tree62da94cd7485706ee2e3608a0e9ecc2235511a35
parent23b09a4f0781483d7f7b0d86376b5f467bca68e9 (diff)
liguist: add support for segmented target in XLIFF
All segments of a translation target are now retrieved. The spacing between the <mrk> is preserved. An auto test is added. Task-number: QTBUG-119051 Change-Id: I16aedcf911642a3372e9676a9896bff39ee99f60 Reviewed-by: Kai Köhne <kai.koehne@qt.io> (cherry picked from commit e96c9e98bc4004063fa93dcf9ccce4997ddb1fdd) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> (cherry picked from commit 1081b84a1c540b5c9c392ef1267eb328d06f97ca)
-rw-r--r--src/linguist/shared/xliff.cpp10
-rw-r--r--tests/auto/linguist/lconvert/data/test-trans_seg.ts.out29
-rw-r--r--tests/auto/linguist/lconvert/data/test-trans_seg.xlf42
-rw-r--r--tests/auto/linguist/lconvert/tst_lconvert.cpp1
4 files changed, 81 insertions, 1 deletions
diff --git a/src/linguist/shared/xliff.cpp b/src/linguist/shared/xliff.cpp
index f54f7758a..ceda53994 100644
--- a/src/linguist/shared/xliff.cpp
+++ b/src/linguist/shared/xliff.cpp
@@ -372,6 +372,7 @@ private:
XC_translator_comment,
XC_restype_context,
XC_restype_translation,
+ XC_mtype_seg_translation,
XC_restype_plurals,
XC_alt_trans
};
@@ -513,6 +514,11 @@ bool XLIFFHandler::startElement(QStringView namespaceURI, QStringView localName,
} else if (localName == QLatin1String("target")) {
if (atts.value(QLatin1String("restype")) != QLatin1String(restypeDummy))
pushContext(XC_restype_translation);
+ } else if (localName == QLatin1String("mrk")) {
+ if (atts.value(QLatin1String("mtype")) == QLatin1String("seg")) {
+ if (currentContext() == XC_restype_translation)
+ pushContext(XC_mtype_seg_translation);
+ }
} else if (localName == QLatin1String("context-group")) {
if (atts.value(QLatin1String("purpose")) == QLatin1String("location"))
pushContext(XC_context_group);
@@ -543,7 +549,7 @@ bool XLIFFHandler::startElement(QStringView namespaceURI, QStringView localName,
pushContext(XC_ph);
}
bail:
- if (currentContext() != XC_ph)
+ if (currentContext() != XC_ph && currentContext() != XC_mtype_seg_translation)
accum.clear();
return true;
}
@@ -581,6 +587,8 @@ bool XLIFFHandler::endElement(QStringView namespaceURI, QStringView localName,
QChar(Translator::BinaryVariantSeparator));
m_translations.append(accum);
}
+ } else if (localName == QLatin1String("mrk")) {
+ popContext(XC_mtype_seg_translation);
} else if (localName == QLatin1String("context-group")) {
if (popContext(XC_context_group)) {
m_refs.append(TranslatorMessage::Reference(
diff --git a/tests/auto/linguist/lconvert/data/test-trans_seg.ts.out b/tests/auto/linguist/lconvert/data/test-trans_seg.ts.out
new file mode 100644
index 000000000..962dd6534
--- /dev/null
+++ b/tests/auto/linguist/lconvert/data/test-trans_seg.ts.out
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!DOCTYPE TS>
+<TS version="2.1" language="de">
+<context>
+ <name></name>
+ <message id="hello_world">
+ <source>Hello world!</source>
+ <translation type="unfinished">Hallo Welt!</translation>
+ </message>
+ <message>
+ <location filename="self" line="137"/>
+ <source>A standout centrepiece for any occasion. Use the temperature sensor for best results.
+
+Serve with roast tomatoes and hasselback potatoes.</source>
+ <translation type="unfinished">Un centro de mesa destacado para cualquier ocasión.Utilice el sensor de temperatura para obtener mejores resultados.
+
+Acompañe con tomates asados y papas horneadas tipo hassleback.</translation>
+ </message>
+ <message>
+ <location filename="self" line="137"/>
+ <source>Two pieces</source>
+ <translation type="unfinished">Zwei Stueck</translation>
+ </message>
+ <message id="test">
+ <source>Hello!</source>
+ <translation type="unfinished">Hallo!</translation>
+ </message>
+</context>
+</TS>
diff --git a/tests/auto/linguist/lconvert/data/test-trans_seg.xlf b/tests/auto/linguist/lconvert/data/test-trans_seg.xlf
new file mode 100644
index 000000000..4cff2bc56
--- /dev/null
+++ b/tests/auto/linguist/lconvert/data/test-trans_seg.xlf
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xliff
+ xmlns="urn:oasis:names:tc:xliff:document:1.2" version="1.2">
+ <file datatype="plaintext" original="self" source-language="en" target-language="de">
+ <body>
+ <trans-unit id="hello_world"
+ xmlns:sap="urn:x-sap:sls-mlt">
+ <source>Hello world!</source>
+ <target>Hallo Welt!</target>
+ </trans-unit>
+ <trans-unit id="_msg2394">
+ <source xml:space="preserve">A standout centrepiece for any occasion. Use the temperature sensor for best results.
+
+Serve with roast tomatoes and hasselback potatoes.</source>
+ <seg-source><mrk mtype="seg" mid="605">A standout centrepiece for any occasion.</mrk><mrk mtype="seg" mid="606">Use the temperature sensor for best results.</mrk>
+
+ <mrk mtype="seg" mid="607">Serve with roast tomatoes and hasselback potatoes.</mrk></seg-source>
+ <target state="signed-off" xml:space="preserve"><mrk mtype="seg" mid="605">Un centro de mesa destacado para cualquier ocasión.</mrk><mrk mtype="seg" mid="606">Utilice el sensor de temperatura para obtener mejores resultados.</mrk>
+
+<mrk mtype="seg" mid="607">Acompañe con tomates asados y papas horneadas tipo hassleback.</mrk></target>
+ <context-group purpose="location">
+ <context context-type="linenumber">137</context>
+ </context-group>
+ </trans-unit>
+ <trans-unit id="_msg2395">
+ <source xml:space="preserve">Two pieces</source>
+ <seg-source>
+ <mrk mtype="seg" mid="1">Two</mrk> <mrk mtype="seg" mid="2">pieces</mrk>
+ </seg-source>
+ <target state="signed-off" xml:space="preserve"><mrk mtype="seg" mid="1">Zwei</mrk> <mrk mtype="seg" mid="2">Stueck</mrk></target>
+ <context-group purpose="location">
+ <context context-type="linenumber">137</context>
+ </context-group>
+ </trans-unit>
+ <trans-unit id="test"
+ xmlns:sap="urn:x-sap:sls-mlt">
+ <source>Hello!</source>
+ <target>Hallo!</target>
+ </trans-unit>
+ </body>
+ </file>
+</xliff>
diff --git a/tests/auto/linguist/lconvert/tst_lconvert.cpp b/tests/auto/linguist/lconvert/tst_lconvert.cpp
index e20d14535..f327bcdb8 100644
--- a/tests/auto/linguist/lconvert/tst_lconvert.cpp
+++ b/tests/auto/linguist/lconvert/tst_lconvert.cpp
@@ -200,6 +200,7 @@ void tst_lconvert::converts_data()
QTest::newRow("broken utf8") << "test-broken-utf8.po" << "test-broken-utf8.po.out" << "po";
QTest::newRow("line joins") << "test-slurp.po" << "test-slurp.po.out" << "po";
QTest::newRow("escapes") << "test-escapes.po" << "test-escapes.po.out" << "po";
+ QTest::newRow("xlf seg") << "test-trans_seg.xlf" << "test-trans_seg.ts.out" << "ts";
}
void tst_lconvert::converts()