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

View File

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