mirror of
https://github.com/parchlinux/calamares.git
synced 2025-06-29 18:35:37 -04:00
[libcalamares] Move LocaleLabel from libcalamaresui to libcalamares
- This isn't a UI-dependent class - Doesn't make much sense in CalamaresUtilsGui either
This commit is contained in:
parent
242d756731
commit
58aa9f4989
5 changed files with 188 additions and 132 deletions
73
src/libcalamares/utils/LocaleLabel.cpp
Normal file
73
src/libcalamares/utils/LocaleLabel.cpp
Normal file
|
@ -0,0 +1,73 @@
|
|||
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
||||
*
|
||||
* Copyright 2014-2015, Teo Mrnjavac <teo@kde.org>
|
||||
* Copyright 2017-2018, 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 "LocaleLabel.h"
|
||||
|
||||
namespace CalamaresUtils
|
||||
{
|
||||
|
||||
LocaleLabel::LocaleLabel()
|
||||
: m_locale( QLocale() )
|
||||
{
|
||||
m_localeId = m_locale.name();
|
||||
|
||||
setLabels( QString(), LabelFormat::IfNeededWithCountry );
|
||||
}
|
||||
|
||||
LocaleLabel::LocaleLabel( const QString& locale, LabelFormat format )
|
||||
: m_locale( LocaleLabel::getLocale( locale ) )
|
||||
, m_localeId( locale )
|
||||
{
|
||||
setLabels( locale, format );
|
||||
}
|
||||
|
||||
void
|
||||
LocaleLabel::setLabels( const QString& locale, LabelFormat format )
|
||||
{
|
||||
//: language[name] (country[name])
|
||||
QString longFormat = QObject::tr( "%1 (%2)" );
|
||||
|
||||
QString languageName = m_locale.nativeLanguageName();
|
||||
QString englishName = m_locale.languageToString( m_locale.language() );
|
||||
QString countryName;
|
||||
|
||||
if ( languageName.isEmpty() )
|
||||
languageName = QString( "* %1 (%2)" ).arg( locale, englishName );
|
||||
|
||||
bool needsCountryName = ( format == LabelFormat::AlwaysWithCountry ) ||
|
||||
(locale.contains( '_' ) && QLocale::countriesForLanguage( m_locale.language() ).count() > 1 );
|
||||
|
||||
if ( needsCountryName )
|
||||
countryName = m_locale.nativeCountryName();
|
||||
m_label = needsCountryName ? longFormat.arg( languageName ).arg( countryName ) : languageName;
|
||||
m_englishLabel = englishName;
|
||||
}
|
||||
|
||||
QLocale LocaleLabel::getLocale( const QString& localeName )
|
||||
{
|
||||
if ( localeName.contains( "@latin" ) )
|
||||
{
|
||||
QLocale loc( localeName ); // Ignores @latin
|
||||
return QLocale( loc.language(), QLocale::Script::LatinScript, loc.country() );
|
||||
}
|
||||
else
|
||||
return QLocale( localeName );
|
||||
}
|
||||
|
||||
} // namespace
|
Loading…
Add table
Add a link
Reference in a new issue