aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/jsruntime/qv4executablecompilationunit.cpp
diff options
context:
space:
mode:
authorLucie Gérard <lucie.gerard@qt.io>2023-10-10 15:33:48 +0200
committerLucie Gérard <lucie.gerard@qt.io>2023-10-26 14:12:00 +0200
commitd6e0d5630a49e9614a70bf960a213b3eff03a68e (patch)
tree1ecb2d4a5064328dfd4d55c27cdf87709470cef1 /src/qml/jsruntime/qv4executablecompilationunit.cpp
parent9187e07d36db8c262b51ba7d1ce35615b31ee918 (diff)
Add pragma syntax to support translation context
Translator pragma can be used to set the translation context instead of having the file name used [ChangeLog][qml][translation][Important Behavior Changes] The context for the translation can now be controled in a given file using pragma Translator. Task-number: QTBUG-114528 Change-Id: I6d9d7fb81ea969a90d8637d7277bdbe96c102088 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'src/qml/jsruntime/qv4executablecompilationunit.cpp')
-rw-r--r--src/qml/jsruntime/qv4executablecompilationunit.cpp13
1 files changed, 10 insertions, 3 deletions
diff --git a/src/qml/jsruntime/qv4executablecompilationunit.cpp b/src/qml/jsruntime/qv4executablecompilationunit.cpp
index bd43d3cb97..e71568b2d8 100644
--- a/src/qml/jsruntime/qv4executablecompilationunit.cpp
+++ b/src/qml/jsruntime/qv4executablecompilationunit.cpp
@@ -976,11 +976,18 @@ QString ExecutableCompilationUnit::translateFrom(TranslationDataIndex index) con
const bool hasContext
= translation.contextIndex != QV4::CompiledData::TranslationData::NoContextIndex;
+ QByteArray context;
+ if (hasContext) {
+ context = stringAt(translation.contextIndex).toUtf8();
+ } else {
+ auto pragmaTranslationContext = data->translationContextIndex();
+ context = stringAt(*pragmaTranslationContext).toUtf8();
+ context = context.isEmpty() ? fileContext() : context;
+ }
+
QByteArray comment = stringAt(translation.commentIndex).toUtf8();
QByteArray text = stringAt(translation.stringIndex).toUtf8();
- return QCoreApplication::translate(
- hasContext ? stringAt(translation.contextIndex).toUtf8() : fileContext(),
- text, comment, translation.number);
+ return QCoreApplication::translate(context, text, comment, translation.number);
#endif
}