[libcalamaresui] Add QDialogButtonBox translation fix

This commit is contained in:
Artem Grinev 2021-12-06 02:26:13 +04:00
parent 6bf0da7230
commit 32c5e18db0
2 changed files with 28 additions and 10 deletions

View File

@ -10,20 +10,15 @@
#include "TranslationFix.h" #include "TranslationFix.h"
#include <QAbstractButton> #include <QAbstractButton>
#include <QPushButton>
#include <QCoreApplication> #include <QCoreApplication>
#include <QMessageBox> #include <QMessageBox>
#include <QDialogButtonBox>
namespace Calamares namespace Calamares
{ {
void //Using QMessageBox's StandardButton enum here but according to headers they should be kept in-sync between multiple classes.
fixButtonLabels( QMessageBox* box )
{
if ( !box )
{
return;
}
static std::pair< decltype( QMessageBox::Ok ), const char* > maps[] = { static std::pair< decltype( QMessageBox::Ok ), const char* > maps[] = {
{ QMessageBox::Ok, QT_TRANSLATE_NOOP( "StandardButtons", "&OK" ) }, { QMessageBox::Ok, QT_TRANSLATE_NOOP( "StandardButtons", "&OK" ) },
{ QMessageBox::Yes, QT_TRANSLATE_NOOP( "StandardButtons", "&Yes" ) }, { QMessageBox::Yes, QT_TRANSLATE_NOOP( "StandardButtons", "&Yes" ) },
@ -32,9 +27,17 @@ fixButtonLabels( QMessageBox* box )
{ QMessageBox::Close, QT_TRANSLATE_NOOP( "StandardButtons", "&Close" ) }, { QMessageBox::Close, QT_TRANSLATE_NOOP( "StandardButtons", "&Close" ) },
}; };
template<typename TButtonBox>
void fixButtonLabels ( TButtonBox* box )
{
if ( !box )
{
return;
}
for ( auto [ sb, label ] : maps ) for ( auto [ sb, label ] : maps )
{ {
auto* button = box->button( sb ); auto* button = box->button( static_cast<typename TButtonBox::StandardButton>(int(sb)) );
if ( button ) if ( button )
{ {
button->setText( QCoreApplication::translate( "StandardButtons", label ) ); button->setText( QCoreApplication::translate( "StandardButtons", label ) );
@ -42,4 +45,16 @@ fixButtonLabels( QMessageBox* box )
} }
} }
void
fixButtonLabels( QMessageBox* box )
{
fixButtonLabels<QMessageBox>(box);
}
void
fixButtonLabels(QDialogButtonBox *box)
{
fixButtonLabels<QDialogButtonBox>(box);
}
} // namespace Calamares } // namespace Calamares

View File

@ -13,6 +13,7 @@
#include "DllMacro.h" #include "DllMacro.h"
class QMessageBox; class QMessageBox;
class QDialogButtonBox;
namespace Calamares namespace Calamares
{ {
@ -26,6 +27,8 @@ namespace Calamares
* guess the context. * guess the context.
*/ */
void UIDLLEXPORT fixButtonLabels( QMessageBox* ); void UIDLLEXPORT fixButtonLabels( QMessageBox* );
void UIDLLEXPORT fixButtonLabels( QDialogButtonBox* );
} // namespace Calamares } // namespace Calamares
#endif #endif