mirror of
https://github.com/parchlinux/calamares.git
synced 2025-02-24 19:05:46 -05:00
Python-i18n: WIP, moving API to libcalamares.utils
This commit is contained in:
parent
1dbe7c29e2
commit
cbfdd8690d
5 changed files with 40 additions and 33 deletions
|
@ -125,33 +125,6 @@ GlobalStoragePythonWrapper::insert( const std::string& key,
|
|||
CalamaresPython::variantFromPyObject( value ) );
|
||||
}
|
||||
|
||||
bp::list
|
||||
GlobalStoragePythonWrapper::gettext_languages() const
|
||||
{
|
||||
bp::list pyList;
|
||||
QVariant localeConf_ = m_gs->value( "localeConf" );
|
||||
if ( localeConf_.canConvert< QVariantMap >() )
|
||||
{
|
||||
QVariant lang_ = localeConf_.value< QVariantMap >()[ "LANG" ];
|
||||
if ( lang_.canConvert< QString >() )
|
||||
{
|
||||
QString lang = lang_.value< QString >();
|
||||
pyList.append( lang.toStdString() );
|
||||
if ( lang.indexOf( '.' ) > 0)
|
||||
{
|
||||
lang.truncate( lang.indexOf( '.' ) );
|
||||
pyList.append( lang.toStdString() );
|
||||
}
|
||||
if ( lang.indexOf( '_' ) > 0)
|
||||
{
|
||||
lang.truncate( lang.indexOf( '_' ) );
|
||||
pyList.append( lang.toStdString() );
|
||||
}
|
||||
}
|
||||
}
|
||||
return pyList;
|
||||
}
|
||||
|
||||
bp::list
|
||||
GlobalStoragePythonWrapper::keys() const
|
||||
{
|
||||
|
|
|
@ -87,10 +87,6 @@ public:
|
|||
int remove( const std::string& key );
|
||||
boost::python::api::object value( const std::string& key ) const;
|
||||
|
||||
// Special case to simplify Python code, gets localeConf["LANG"]
|
||||
// from the global store, in list form with language variants
|
||||
// expanded (e.g [ "en_GB.UTF-8", "en_GB", "en" ] ).
|
||||
boost::python::list gettext_languages() const;
|
||||
private:
|
||||
Calamares::GlobalStorage* m_gs;
|
||||
};
|
||||
|
|
|
@ -86,8 +86,7 @@ BOOST_PYTHON_MODULE( libcalamares )
|
|||
.def( "insert", &CalamaresPython::GlobalStoragePythonWrapper::insert )
|
||||
.def( "keys", &CalamaresPython::GlobalStoragePythonWrapper::keys )
|
||||
.def( "remove", &CalamaresPython::GlobalStoragePythonWrapper::remove )
|
||||
.def( "value", &CalamaresPython::GlobalStoragePythonWrapper::value )
|
||||
.def( "gettext_languages", &CalamaresPython::GlobalStoragePythonWrapper::gettext_languages );
|
||||
.def( "value", &CalamaresPython::GlobalStoragePythonWrapper::value );
|
||||
|
||||
// libcalamares.utils submodule starts here
|
||||
bp::object utilsModule( bp::handle<>( bp::borrowed( PyImport_AddModule( "libcalamares.utils" ) ) ) );
|
||||
|
@ -217,6 +216,14 @@ BOOST_PYTHON_MODULE( libcalamares )
|
|||
"Applying the function to a string obscured by this function will result "
|
||||
"in the original string."
|
||||
);
|
||||
|
||||
|
||||
bp::def(
|
||||
"gettext_languages",
|
||||
&CalamaresPython::gettext_languages,
|
||||
bp::args(),
|
||||
"Returns list of languages (most to least-specific) for gettext."
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -208,4 +208,31 @@ obscure( const std::string& string )
|
|||
return CalamaresUtils::obscure( QString::fromStdString( string ) ).toStdString();
|
||||
}
|
||||
|
||||
std::list< std::string >
|
||||
gettext_languages()
|
||||
{
|
||||
bp::list pyList;
|
||||
QVariant localeConf_ = m_gs->value( "localeConf" );
|
||||
if ( localeConf_.canConvert< QVariantMap >() )
|
||||
{
|
||||
QVariant lang_ = localeConf_.value< QVariantMap >()[ "LANG" ];
|
||||
if ( lang_.canConvert< QString >() )
|
||||
{
|
||||
QString lang = lang_.value< QString >();
|
||||
pyList.append( lang.toStdString() );
|
||||
if ( lang.indexOf( '.' ) > 0)
|
||||
{
|
||||
lang.truncate( lang.indexOf( '.' ) );
|
||||
pyList.append( lang.toStdString() );
|
||||
}
|
||||
if ( lang.indexOf( '_' ) > 0)
|
||||
{
|
||||
lang.truncate( lang.indexOf( '_' ) );
|
||||
pyList.append( lang.toStdString() );
|
||||
}
|
||||
}
|
||||
}
|
||||
return pyList;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -61,6 +61,10 @@ std::string check_target_env_output( const boost::python::list& args,
|
|||
|
||||
std::string obscure( const std::string& string );
|
||||
|
||||
std::string gettext_path();
|
||||
|
||||
std::list< std::string > gettext_languages();
|
||||
|
||||
void debug( const std::string& s );
|
||||
|
||||
inline int _handle_check_target_env_call_error( int ec, const QString& cmd );
|
||||
|
|
Loading…
Add table
Reference in a new issue