Python-i18n: implement gettext functions in libcalamares.utils

- remove Job.gettextPath
 - add libcalamares.utils.gettext_path()
 - add libcalamares.utils.gettext_lang()
 - modify examples in main.py
 - add some gettext debug-output from dummypython
 - correct namespace mis-labeling
 - provide two forms of GlobalStorage
   - regular use, has a JobQueue with storage
   - testing use, creates GlobalStorage separately, provide
     independent access to that for Python.
This commit is contained in:
Adriaan de Groot 2017-08-15 22:50:26 +02:00
parent 5326e9ee06
commit 74be2fd098
7 changed files with 55 additions and 21 deletions

View file

@ -186,14 +186,6 @@ PythonJobInterface::PythonJobInterface( Calamares::PythonJob* parent )
prettyName = m_parent->prettyName().toStdString();
workingPath = m_parent->m_workingPath.toStdString();
configuration = CalamaresPython::variantMapToPyDict( m_parent->m_configurationMap );
if (moduleDir.cd("../_lang/python"))
gettextPath = moduleDir.absolutePath().toStdString();
else
{
debug( "No _lang/ directory for translations." );
gettextPath = std::string();
}
}
@ -211,31 +203,50 @@ obscure( const std::string& string )
return CalamaresUtils::obscure( QString::fromStdString( string ) ).toStdString();
}
std::list< std::string >
bp::list
gettext_languages()
{
std::list< std::string > pyList;
QVariant localeConf_ = Calamares::JobQueue::instance()->globalStorage()->value( "localeConf" );
bp::list pyList;
// There are two ways that Python jobs can be initialised:
// - through JobQueue, in which case that has an instance which holds
// a GlobalStorage object, or
// - through the Python test-script, which initialises its
// own GlobalStoragePythonWrapper, which then holds a
// GlobalStorage object for all of Python.
Calamares::JobQueue* jq = Calamares::JobQueue::instance();
Calamares::GlobalStorage* gs = jq ? jq->globalStorage() : CalamaresPython::GlobalStoragePythonWrapper::globalStorageInstance();
QVariant localeConf_ = gs->value( "localeConf" );
if ( localeConf_.canConvert< QVariantMap >() )
{
QVariant lang_ = localeConf_.value< QVariantMap >()[ "LANG" ];
if ( lang_.canConvert< QString >() )
{
QString lang = lang_.value< QString >();
pyList.push_back( lang.toStdString() );
pyList.append( lang.toStdString() );
if ( lang.indexOf( '.' ) > 0)
{
lang.truncate( lang.indexOf( '.' ) );
pyList.push_back( lang.toStdString() );
pyList.append( lang.toStdString() );
}
if ( lang.indexOf( '_' ) > 0)
{
lang.truncate( lang.indexOf( '_' ) );
pyList.push_back( lang.toStdString() );
pyList.append( lang.toStdString() );
}
}
}
return pyList;
}
std::string
gettext_path()
{
// TODO: distinguish between -d runs and normal runs
// TODO: can we detect DESTDIR-installs?
return std::string();
}
}