i18n: introduce a "TranslationFix"

This is intended to apply translations to some common Qt UI components.

Example: a QMessageBox with standard buttons OK and Cancel; the text
for that is determined at startup using the system locale, and later
changes to the current locale or the current translation catalog,
do not affect OK and Cancel. It might be possible to load a catalog
with the right translation strings, except that there is no way to
know what the context or catalog **is** for the strings that are
used to label standard buttons: they can come from Qt base, or
the platform, or the theme. Merely loading the Qt Base translations
for the correct language does not help, because those translations
do not contain an "OK" string with the context used for standard
buttons.

Do the translation by hand; then we have all of the Calamares
languages covered, too, which is more than the Qt translations do.
main
Adriaan de Groot 4 years ago
parent 438302fcf5
commit 683bad19fc

@ -29,6 +29,7 @@ set( calamaresui_SOURCES
widgets/ClickableLabel.cpp
widgets/FixedAspectRatioLabel.cpp
widgets/PrettyRadioButton.cpp
widgets/TranslationFix.cpp
widgets/WaitingWidget.cpp
${CMAKE_SOURCE_DIR}/3rdparty/waitingspinnerwidget.cpp

@ -0,0 +1,40 @@
/* === This file is part of Calamares - <https://calamares.io> ===
*
* SPDX-FileCopyrightText: 2021 Adriaan de Groot <groot@kde.org>
* SPDX-License-Identifier: GPL-3.0-or-later
*
* Calamares is Free Software: see the License-Identifier above.
*
*/
#include "TranslationFix.h"
#include <QAbstractButton>
#include <QCoreApplication>
#include <QMessageBox>
namespace Calamares
{
void
fixButtonLabels( QMessageBox* box )
{
if ( !box )
{
return;
}
static std::pair< decltype( QMessageBox::Ok ), const char* > maps[]
= { { QMessageBox::Ok, QT_TRANSLATE_NOOP( "StandardButtons", "&OK" ) } };
for ( auto [ sb, label ] : maps )
{
auto* button = box->button( sb );
if ( button )
{
button->setText( QCoreApplication::translate( "StandardButtons", label ) );
}
}
}
} // namespace Calamares

@ -0,0 +1,31 @@
/* === This file is part of Calamares - <https://calamares.io> ===
*
* SPDX-FileCopyrightText: 2021 Adriaan de Groot <groot@kde.org>
* SPDX-License-Identifier: GPL-3.0-or-later
*
* Calamares is Free Software: see the License-Identifier above.
*
*/
#ifndef LIBCALAMARESUI_WIDGETS_TRANSLATIONFIX_H
#define LIBCALAMARESUI_WIDGETS_TRANSLATIONFIX_H
#include "DllMacro.h"
class QMessageBox;
namespace Calamares
{
/** @brief Fixes the labels on the standard buttons of the message box
*
* Updates OK / Cancel / Yes / No because there does not
* seem to be a way to do so in the Retranslator code
* (in libcalamares) since the translated strings may come
* from a variety of platform-plugin sources and we can't
* guess the context.
*/
void UIDLLEXPORT fixButtonLabels( QMessageBox* );
} // namespace Calamares
#endif

@ -26,6 +26,7 @@
#include "utils/Logger.h"
#include "utils/NamedEnum.h"
#include "utils/Retranslator.h"
#include "widgets/TranslationFix.h"
#include <QApplication>
#include <QBoxLayout>
@ -251,6 +252,7 @@ WelcomePage::showAboutBox()
.arg( Calamares::Branding::instance()->versionedName() ),
QMessageBox::Ok,
this );
Calamares::fixButtonLabels( &mb );
mb.setIconPixmap( CalamaresUtils::defaultPixmap(
CalamaresUtils::Squid,
CalamaresUtils::Original,

Loading…
Cancel
Save