[libcalamaresui] Add QDialogButtonBox translation fix
This commit is contained in:
parent
6bf0da7230
commit
32c5e18db0
@ -10,20 +10,15 @@
|
||||
#include "TranslationFix.h"
|
||||
|
||||
#include <QAbstractButton>
|
||||
#include <QPushButton>
|
||||
#include <QCoreApplication>
|
||||
#include <QMessageBox>
|
||||
#include <QDialogButtonBox>
|
||||
|
||||
namespace Calamares
|
||||
{
|
||||
|
||||
void
|
||||
fixButtonLabels( QMessageBox* box )
|
||||
{
|
||||
if ( !box )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//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" ) },
|
||||
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user