[libcalamares] Expose a translations-loading function

This commit is contained in:
Adriaan de Groot 2020-10-30 13:58:17 +01:00
parent ac6c9fae4a
commit 7659dfdb9d
2 changed files with 29 additions and 1 deletions

View File

@ -195,7 +195,7 @@ installTranslator( const QLocale& locale, const QString& brandingTranslationsPre
loadSingletonTranslator( TZLoader( locale ), s_tztranslator );
loadSingletonTranslator( CalamaresLoader( locale ), s_translator );
s_translatorLocaleName = CalamaresLoader::mungeLocaleName( locale );
s_translatorLocaleName = CalamaresLoader::mungeLocaleName(locale);
}
@ -205,6 +205,12 @@ translatorLocaleName()
return s_translatorLocaleName;
}
bool
loadTranslator( const QLocale& locale, const QString& prefix, QTranslator *translator )
{
return ::tryLoad( translator, prefix, locale.name() );
}
Retranslator*
Retranslator::retranslatorFor( QObject* parent )
{

View File

@ -21,6 +21,7 @@
class QEvent;
class QLocale;
class QTranslator;
namespace CalamaresUtils
{
@ -31,8 +32,29 @@ namespace CalamaresUtils
*/
DLLEXPORT void installTranslator( const QLocale& locale, const QString& brandingTranslationsPrefix );
/** @brief The name of the (locale of the) most recently installed translator
*
* May return something different from the locale.name() of the
* QLocale passed in, because Calamares will munge some names and
* may remap translations.
*/
DLLEXPORT QString translatorLocaleName();
/** @brief Loads <prefix><locale> translations into the given @p translator
*
* This function is not intended for general use: it is for those special
* cases where modules need their own translator / translations for data
* that is locale to the module. Tries to load a .qm from "sensible"
* locations, which are the same ones that installTranslator() would use.
* Takes local-translations into account.
*
* Note that @p prefix should end with an underscore '_' -- this function
* does not introduce one by itself.
*
* @returns @c true on success
*/
DLLEXPORT bool loadTranslator( const QLocale& locale, const QString& prefix, QTranslator* translator );
/** @brief Set @p allow to true to load translations from current dir.
*
* If false, (or never called) the translations are loaded only from