2019-08-04 22:56:41 +02:00
|
|
|
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
|
|
|
*
|
|
|
|
* Copyright 2019, Adriaan de Groot <groot@kde.org>
|
|
|
|
*
|
|
|
|
* Calamares is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Calamares is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "TranslatableConfiguration.h"
|
|
|
|
|
|
|
|
#include "LabelModel.h"
|
|
|
|
|
|
|
|
#include "utils/Logger.h"
|
|
|
|
#include "utils/Variant.h"
|
|
|
|
|
|
|
|
#include <QRegularExpression>
|
|
|
|
#include <QRegularExpressionMatch>
|
|
|
|
|
|
|
|
namespace CalamaresUtils
|
|
|
|
{
|
|
|
|
namespace Locale
|
|
|
|
{
|
|
|
|
TranslatedString::TranslatedString(const QString& string)
|
|
|
|
{
|
|
|
|
m_strings[QString()]=string;
|
|
|
|
}
|
|
|
|
TranslatedString::TranslatedString(const QVariantMap& map, const QString& key)
|
|
|
|
{
|
|
|
|
// Get the un-decorated value for the key
|
|
|
|
QString value = CalamaresUtils::getString( map, key );
|
|
|
|
if ( value.isEmpty() )
|
|
|
|
{
|
|
|
|
value = key;
|
|
|
|
}
|
|
|
|
m_strings[QString()] = value;
|
|
|
|
|
2019-08-05 17:57:32 +02:00
|
|
|
for ( auto it = map.constKeyValueBegin(); it != map.constKeyValueEnd(); ++it )
|
2019-08-04 22:56:41 +02:00
|
|
|
{
|
|
|
|
QString subkey = (*it).first;
|
|
|
|
if ( subkey == key )
|
|
|
|
{
|
|
|
|
// Already obtained, above
|
|
|
|
}
|
|
|
|
else if ( subkey.startsWith( key ) )
|
|
|
|
{
|
|
|
|
QRegularExpressionMatch match;
|
|
|
|
if ( subkey.indexOf( QRegularExpression("\\[([a-zA-Z_@]*)\\]"), 0, &match ) > 0 )
|
|
|
|
{
|
|
|
|
QString language = match.captured(1);
|
2019-08-05 17:57:32 +02:00
|
|
|
m_strings[language] = (*it).second.toString();
|
2019-08-04 22:56:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-05 23:37:25 +02:00
|
|
|
QString TranslatedString::get() const
|
|
|
|
{
|
|
|
|
return get( QLocale() );
|
|
|
|
}
|
|
|
|
|
|
|
|
QString TranslatedString::get(const QLocale& locale) const
|
|
|
|
{
|
|
|
|
cDebug() << "Getting locale" << locale.name();
|
|
|
|
return m_strings[QString()];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-08-04 22:56:41 +02:00
|
|
|
} // namespace Locale
|
|
|
|
} // namespace CalamaresUtils
|