File indexing completed on 2024-11-24 03:56:28

0001 /*
0002  * SPDX-FileCopyrightText: 2019-2023 Mattia Basaglia <dev@dragon.best>
0003  *
0004  * SPDX-License-Identifier: GPL-3.0-or-later
0005  */
0006 
0007 #pragma once
0008 
0009 #include <QObject>
0010 #include <QCoreApplication>
0011 
0012 namespace app::utils {
0013 
0014 class TranslatedString
0015 {
0016 public:
0017     // Invoke using QT_TRANSLATE_NOOP("Settings", "")
0018     TranslatedString(const char* input) : input(input) {}
0019     TranslatedString(const QString& already_translated) : already_translated(std::move(already_translated)) {}
0020 
0021     TranslatedString() = default;
0022 
0023     operator QString() const
0024     {
0025         if ( !input || input[0] == '\0' )
0026             return already_translated;
0027         return QCoreApplication::translate("Settings", input);
0028     };
0029 
0030 private:
0031     const char* input = nullptr;
0032     QString already_translated;
0033 };
0034 
0035 } // namespace app::utils