From e541a3f099798e2258116d3c031b35274d789783 Mon Sep 17 00:00:00 2001 From: Kai Koehne Date: Thu, 30 Jan 2020 11:08:50 +0100 Subject: QTranslator: Expose language of translation file This allows for instance to show the current UI language in the UI, or to load additional translations that match the .qm file by other means. This is especially useful in the case of QTranslator::load(QLocale(), ...), in which case different language and country combinations might be tried. Another option is to inspect the file name via QTranslator::filePath(); however, this is more error-prone, and might also miss information (if the .qm file name doesn't have a country suffix, or no suffix at all). Change-Id: I6f565d53d8f50e21241ccae6c4de264747ac8f81 Reviewed-by: Simon Hausmann --- tests/auto/corelib/kernel/qtranslator/hellotr_la.qm | Bin 230 -> 237 bytes .../auto/corelib/kernel/qtranslator/tst_qtranslator.cpp | 9 +++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) (limited to 'tests/auto/corelib/kernel/qtranslator') diff --git a/tests/auto/corelib/kernel/qtranslator/hellotr_la.qm b/tests/auto/corelib/kernel/qtranslator/hellotr_la.qm index cc42afe05c..25c0aad583 100644 Binary files a/tests/auto/corelib/kernel/qtranslator/hellotr_la.qm and b/tests/auto/corelib/kernel/qtranslator/hellotr_la.qm differ diff --git a/tests/auto/corelib/kernel/qtranslator/tst_qtranslator.cpp b/tests/auto/corelib/kernel/qtranslator/tst_qtranslator.cpp index cc0f97139f..9fde7da816 100644 --- a/tests/auto/corelib/kernel/qtranslator/tst_qtranslator.cpp +++ b/tests/auto/corelib/kernel/qtranslator/tst_qtranslator.cpp @@ -110,9 +110,10 @@ void tst_QTranslator::load_data() QTest::addColumn("filepath"); QTest::addColumn("isEmpty"); QTest::addColumn("translation"); + QTest::addColumn("language"); - QTest::newRow("hellotr_la") << "hellotr_la.qm" << false << "Hallo Welt!"; - QTest::newRow("hellotr_empty") << "hellotr_empty.qm" << true << ""; + QTest::newRow("hellotr_la") << "hellotr_la.qm" << false << "Hallo Welt!" << "de"; + QTest::newRow("hellotr_empty") << "hellotr_empty.qm" << true << "" << ""; } void tst_QTranslator::load() @@ -120,6 +121,7 @@ void tst_QTranslator::load() QFETCH(QString, filepath); QFETCH(bool, isEmpty); QFETCH(QString, translation); + QFETCH(QString, language); { QTranslator tor; @@ -127,6 +129,7 @@ void tst_QTranslator::load() QCOMPARE(tor.isEmpty(), isEmpty); QCOMPARE(tor.translate("QPushButton", "Hello world!"), translation); QCOMPARE(tor.filePath(), filepath); + QCOMPARE(tor.language(), language); } { @@ -138,6 +141,7 @@ void tst_QTranslator::load() QCOMPARE(tor.isEmpty(), isEmpty); QCOMPARE(tor.translate("QPushButton", "Hello world!"), translation); QCOMPARE(tor.filePath(), ""); + QCOMPARE(tor.language(), language); } { @@ -147,6 +151,7 @@ void tst_QTranslator::load() QCOMPARE(tor.isEmpty(), isEmpty); QCOMPARE(tor.translate("QPushButton", "Hello world!"), translation); QCOMPARE(tor.filePath(), path); + QCOMPARE(tor.language(), language); } } -- cgit v1.2.3