Python-i18n: WIP, moving API to libcalamares.utils
This commit is contained in:
parent
1dbe7c29e2
commit
cbfdd8690d
@ -125,33 +125,6 @@ GlobalStoragePythonWrapper::insert( const std::string& key,
|
|||||||
CalamaresPython::variantFromPyObject( value ) );
|
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
|
bp::list
|
||||||
GlobalStoragePythonWrapper::keys() const
|
GlobalStoragePythonWrapper::keys() const
|
||||||
{
|
{
|
||||||
|
@ -87,10 +87,6 @@ public:
|
|||||||
int remove( const std::string& key );
|
int remove( const std::string& key );
|
||||||
boost::python::api::object value( const std::string& key ) const;
|
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:
|
private:
|
||||||
Calamares::GlobalStorage* m_gs;
|
Calamares::GlobalStorage* m_gs;
|
||||||
};
|
};
|
||||||
|
@ -86,8 +86,7 @@ BOOST_PYTHON_MODULE( libcalamares )
|
|||||||
.def( "insert", &CalamaresPython::GlobalStoragePythonWrapper::insert )
|
.def( "insert", &CalamaresPython::GlobalStoragePythonWrapper::insert )
|
||||||
.def( "keys", &CalamaresPython::GlobalStoragePythonWrapper::keys )
|
.def( "keys", &CalamaresPython::GlobalStoragePythonWrapper::keys )
|
||||||
.def( "remove", &CalamaresPython::GlobalStoragePythonWrapper::remove )
|
.def( "remove", &CalamaresPython::GlobalStoragePythonWrapper::remove )
|
||||||
.def( "value", &CalamaresPython::GlobalStoragePythonWrapper::value )
|
.def( "value", &CalamaresPython::GlobalStoragePythonWrapper::value );
|
||||||
.def( "gettext_languages", &CalamaresPython::GlobalStoragePythonWrapper::gettext_languages );
|
|
||||||
|
|
||||||
// libcalamares.utils submodule starts here
|
// libcalamares.utils submodule starts here
|
||||||
bp::object utilsModule( bp::handle<>( bp::borrowed( PyImport_AddModule( "libcalamares.utils" ) ) ) );
|
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 "
|
"Applying the function to a string obscured by this function will result "
|
||||||
"in the original string."
|
"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();
|
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 obscure( const std::string& string );
|
||||||
|
|
||||||
|
std::string gettext_path();
|
||||||
|
|
||||||
|
std::list< std::string > gettext_languages();
|
||||||
|
|
||||||
void debug( const std::string& s );
|
void debug( const std::string& s );
|
||||||
|
|
||||||
inline int _handle_check_target_env_call_error( int ec, const QString& cmd );
|
inline int _handle_check_target_env_call_error( int ec, const QString& cmd );
|
||||||
|
Loading…
Reference in New Issue
Block a user