|
|
|
@ -58,7 +58,7 @@ struct TranslationLoader
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
virtual ~TranslationLoader() {};
|
|
|
|
|
virtual ~TranslationLoader();
|
|
|
|
|
/// @brief Loads @p translator with the specific translations of this type
|
|
|
|
|
virtual bool tryLoad( QTranslator* translator ) = 0;
|
|
|
|
|
|
|
|
|
@ -66,6 +66,7 @@ struct TranslationLoader
|
|
|
|
|
QString m_localeName;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/// @brief Loads translations for branding
|
|
|
|
|
struct BrandingLoader : public TranslationLoader
|
|
|
|
|
{
|
|
|
|
|
BrandingLoader( const QLocale& locale, const QString& prefix )
|
|
|
|
@ -74,74 +75,85 @@ struct BrandingLoader : public TranslationLoader
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool tryLoad( QTranslator* translator ) override
|
|
|
|
|
{
|
|
|
|
|
if ( m_prefix.isEmpty() )
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
QString brandingTranslationsDirPath( m_prefix );
|
|
|
|
|
brandingTranslationsDirPath.truncate( m_prefix.lastIndexOf( QDir::separator() ) );
|
|
|
|
|
QDir brandingTranslationsDir( brandingTranslationsDirPath );
|
|
|
|
|
if ( brandingTranslationsDir.exists() )
|
|
|
|
|
{
|
|
|
|
|
QString filenameBase( m_prefix );
|
|
|
|
|
filenameBase.remove( 0, m_prefix.lastIndexOf( QDir::separator() ) + 1 );
|
|
|
|
|
if ( translator->load( m_locale, filenameBase, "_", brandingTranslationsDir.absolutePath() ) )
|
|
|
|
|
{
|
|
|
|
|
cDebug() << Logger::SubEntry << "Branding using locale:" << m_localeName;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
cDebug() << Logger::SubEntry << "Branding using default, system locale not found:" << m_localeName;
|
|
|
|
|
// TODO: this loads something completely different
|
|
|
|
|
return translator->load( m_prefix + "en" );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
bool tryLoad( QTranslator* translator ) override;
|
|
|
|
|
|
|
|
|
|
QString m_prefix;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/// @brief Loads regular Calamares translations (program text)
|
|
|
|
|
struct CalamaresLoader : public TranslationLoader
|
|
|
|
|
{
|
|
|
|
|
using TranslationLoader::TranslationLoader;
|
|
|
|
|
|
|
|
|
|
bool tryLoad( QTranslator* translator ) override
|
|
|
|
|
{
|
|
|
|
|
if ( translator->load( QString( ":/lang/calamares_" ) + m_localeName ) )
|
|
|
|
|
{
|
|
|
|
|
cDebug() << Logger::SubEntry << "Calamares using locale:" << m_localeName;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
cDebug() << Logger::SubEntry << "Calamares using default, system locale not found:" << m_localeName;
|
|
|
|
|
return translator->load( QString( ":/lang/calamares_en" ) );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
bool tryLoad( QTranslator* translator ) override;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/// @brief Loads timezone name translations
|
|
|
|
|
struct TZLoader : public TranslationLoader
|
|
|
|
|
{
|
|
|
|
|
using TranslationLoader::TranslationLoader;
|
|
|
|
|
bool tryLoad( QTranslator* translator ) override
|
|
|
|
|
bool tryLoad( QTranslator* translator ) override;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
TranslationLoader::~TranslationLoader() {}
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
BrandingLoader::tryLoad( QTranslator* translator )
|
|
|
|
|
{
|
|
|
|
|
if ( m_prefix.isEmpty() )
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
QString brandingTranslationsDirPath( m_prefix );
|
|
|
|
|
brandingTranslationsDirPath.truncate( m_prefix.lastIndexOf( QDir::separator() ) );
|
|
|
|
|
QDir brandingTranslationsDir( brandingTranslationsDirPath );
|
|
|
|
|
if ( brandingTranslationsDir.exists() )
|
|
|
|
|
{
|
|
|
|
|
if ( translator->load( QString( ":/lang/tz_" ) + m_localeName ) )
|
|
|
|
|
QString filenameBase( m_prefix );
|
|
|
|
|
filenameBase.remove( 0, m_prefix.lastIndexOf( QDir::separator() ) + 1 );
|
|
|
|
|
if ( translator->load( m_locale, filenameBase, "_", brandingTranslationsDir.absolutePath() ) )
|
|
|
|
|
{
|
|
|
|
|
cDebug() << Logger::SubEntry << "Calamares Timezones using locale:" << m_localeName;
|
|
|
|
|
cDebug() << Logger::SubEntry << "Branding using locale:" << m_localeName;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
cDebug() << Logger::SubEntry
|
|
|
|
|
<< "Calamares Timezones using default, system locale not found:" << m_localeName;
|
|
|
|
|
return translator->load( QString( ":/lang/tz_en" ) );
|
|
|
|
|
cDebug() << Logger::SubEntry << "Branding using default, system locale not found:" << m_localeName;
|
|
|
|
|
// TODO: this loads something completely different
|
|
|
|
|
return translator->load( m_prefix + "en" );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
CalamaresLoader::tryLoad( QTranslator* translator )
|
|
|
|
|
{
|
|
|
|
|
if ( translator->load( QString( ":/lang/calamares_" ) + m_localeName ) )
|
|
|
|
|
{
|
|
|
|
|
cDebug() << Logger::SubEntry << "Calamares using locale:" << m_localeName;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
cDebug() << Logger::SubEntry << "Calamares using default, system locale not found:" << m_localeName;
|
|
|
|
|
return translator->load( QString( ":/lang/calamares_en" ) );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
TZLoader::tryLoad( QTranslator* translator )
|
|
|
|
|
{
|
|
|
|
|
if ( translator->load( QString( ":/lang/tz_" ) + m_localeName ) )
|
|
|
|
|
{
|
|
|
|
|
cDebug() << Logger::SubEntry << "Calamares Timezones using locale:" << m_localeName;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
cDebug() << Logger::SubEntry << "Calamares Timezones using default, system locale not found:" << m_localeName;
|
|
|
|
|
return translator->load( QString( ":/lang/tz_en" ) );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
loadSingletonTranslator( TranslationLoader&& loader, QTranslator*& translator_p )
|
|
|
|
@ -167,7 +179,7 @@ static QTranslator* s_tztranslator = nullptr;
|
|
|
|
|
static QString s_translatorLocaleName;
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
installTranslator( const QLocale& locale, const QString& brandingTranslationsPrefix, QObject* parent )
|
|
|
|
|
installTranslator( const QLocale& locale, const QString& brandingTranslationsPrefix, QObject* )
|
|
|
|
|
{
|
|
|
|
|
loadSingletonTranslator( BrandingLoader( locale, brandingTranslationsPrefix ), s_brandingTranslator );
|
|
|
|
|
loadSingletonTranslator( TZLoader( locale ), s_tztranslator );
|
|
|
|
|