[libcalamares] Test the translated string with real translations
- introduce a bogus translation context, load translations, and check that the context-enabled translator does its job.
This commit is contained in:
parent
0143aa5515
commit
cfbe722350
@ -215,10 +215,29 @@ calamares_add_test(
|
||||
${geoip_src}
|
||||
)
|
||||
|
||||
# Build up translations for this one test
|
||||
set( trans_file "localetest" )
|
||||
set( trans_infile ${CMAKE_CURRENT_BINARY_DIR}/${trans_file}.qrc )
|
||||
set( trans_outfile ${CMAKE_CURRENT_BINARY_DIR}/qrc_${trans_file}.cxx )
|
||||
set( calamares_i18n_qrc_content "<file>localetest_nl.qm</file>" )
|
||||
configure_file( ${CMAKE_SOURCE_DIR}/lang/calamares_i18n.qrc.in ${trans_infile} @ONLY )
|
||||
|
||||
qt5_add_translation(QM_FILES "${CMAKE_CURRENT_SOURCE_DIR}/testdata/localetest_nl.ts")
|
||||
|
||||
# Run the resource compiler (rcc_options should already be set)
|
||||
add_custom_command(
|
||||
OUTPUT ${trans_outfile}
|
||||
COMMAND "${Qt5Core_RCC_EXECUTABLE}"
|
||||
ARGS ${rcc_options} --format-version 1 -name ${trans_file} -o ${trans_outfile} ${trans_infile}
|
||||
MAIN_DEPENDENCY ${trans_infile}
|
||||
DEPENDS ${QM_FILES}
|
||||
)
|
||||
|
||||
calamares_add_test(
|
||||
libcalamareslocaletest
|
||||
SOURCES
|
||||
locale/Tests.cpp
|
||||
${trans_outfile}
|
||||
)
|
||||
|
||||
calamares_add_test(
|
||||
|
@ -16,6 +16,7 @@
|
||||
#include "CalamaresVersion.h"
|
||||
#include "GlobalStorage.h"
|
||||
#include "utils/Logger.h"
|
||||
#include "utils/Retranslator.h"
|
||||
|
||||
#include <QtTest/QtTest>
|
||||
|
||||
@ -33,6 +34,7 @@ private Q_SLOTS:
|
||||
void testTranslatableLanguages();
|
||||
void testTranslatableConfig1();
|
||||
void testTranslatableConfig2();
|
||||
void testTranslatableConfigContext();
|
||||
void testLanguageScripts();
|
||||
|
||||
void testEsperanto();
|
||||
@ -246,6 +248,32 @@ LocaleTests::testTranslatableConfig2()
|
||||
QCOMPARE( ts3.count(), 1 ); // The empty string
|
||||
}
|
||||
|
||||
void
|
||||
LocaleTests::testTranslatableConfigContext()
|
||||
{
|
||||
using TS = CalamaresUtils::Locale::TranslatedString;
|
||||
|
||||
const QString original( "Quit" );
|
||||
TS quitUntranslated( original );
|
||||
TS quitTranslated( original, metaObject()->className() );
|
||||
|
||||
QCOMPARE( quitUntranslated.get(), original );
|
||||
QCOMPARE( quitTranslated.get(), original );
|
||||
|
||||
// Load translation data from QRC
|
||||
QVERIFY( QFile::exists( ":/lang/localetest_nl.qm" ) );
|
||||
QTranslator t;
|
||||
QVERIFY( t.load( QString( ":/lang/localetest_nl" ) ) );
|
||||
QCoreApplication::installTranslator( &t );
|
||||
|
||||
// Translation doesn't affect the one without context
|
||||
QCOMPARE( quitUntranslated.get(), original );
|
||||
// But the translation **does** affect this class' context
|
||||
QCOMPARE( quitTranslated.get(), QStringLiteral( "Ophouden" ) );
|
||||
QCOMPARE( tr( "Quit" ), QStringLiteral( "Ophouden" ) );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
LocaleTests::testRegions()
|
||||
{
|
||||
|
15
src/libcalamares/testdata/localetest_nl.ts
vendored
Normal file
15
src/libcalamares/testdata/localetest_nl.ts
vendored
Normal file
@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- SPDX-FileCopyrightText: no
|
||||
SPDX-License-Identifier: CC0-1.0
|
||||
-->
|
||||
<!DOCTYPE TS>
|
||||
<TS language="nl" version="2.1">
|
||||
<context>
|
||||
<name>LocaleTests</name>
|
||||
<message>
|
||||
<location filename="Tests.cpp" line="22"/>
|
||||
<source>Quit</source>
|
||||
<translation>Ophouden</translation>
|
||||
</message>
|
||||
</context>
|
||||
</TS>
|
Loading…
Reference in New Issue
Block a user