Python-i18n: add a gettext_path for python job modules
This commit is contained in:
parent
9f5ff55ba2
commit
b922d88b0f
@ -57,10 +57,13 @@ macro(add_calamares_python_translations language)
|
|||||||
if( lang STREQUAL "en" )
|
if( lang STREQUAL "en" )
|
||||||
message( STATUS "Skipping Python translations for en_US" )
|
message( STATUS "Skipping Python translations for en_US" )
|
||||||
else()
|
else()
|
||||||
list( APPEND TS_FILES "${CMAKE_SOURCE_DIR}/lang/python_${lang}.po;${CMAKE_SOURCE_DIR}/lang/python_${lang}.mo" )
|
list( APPEND TS_FILES "${CMAKE_SOURCE_DIR}/lang/python/${lang}/LC_MESSAGES/python.po;${CMAKE_SOURCE_DIR}/lang/python/${lang}/LC_MESSAGES/python.mo" )
|
||||||
endif()
|
endif()
|
||||||
endforeach()
|
endforeach()
|
||||||
|
|
||||||
|
file( MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/_lang )
|
||||||
|
file( COPY ${CMAKE_SOURCE_DIR}/lang/python DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/_lang )
|
||||||
|
|
||||||
install(
|
install(
|
||||||
FILES ${TS_FILES}
|
FILES ${TS_FILES}
|
||||||
DESTINATION ${CMAKE_INSTALL_DATADIR}/calamares/lang/
|
DESTINATION ${CMAKE_INSTALL_DATADIR}/calamares/lang/
|
||||||
|
@ -125,6 +125,32 @@ 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
|
||||||
|
@ -86,6 +86,11 @@ public:
|
|||||||
boost::python::list keys() const;
|
boost::python::list keys() const;
|
||||||
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;
|
||||||
};
|
};
|
||||||
|
@ -70,6 +70,7 @@ BOOST_PYTHON_MODULE( libcalamares )
|
|||||||
.def_readonly( "module_name", &CalamaresPython::PythonJobInterface::moduleName )
|
.def_readonly( "module_name", &CalamaresPython::PythonJobInterface::moduleName )
|
||||||
.def_readonly( "pretty_name", &CalamaresPython::PythonJobInterface::prettyName )
|
.def_readonly( "pretty_name", &CalamaresPython::PythonJobInterface::prettyName )
|
||||||
.def_readonly( "working_path", &CalamaresPython::PythonJobInterface::workingPath )
|
.def_readonly( "working_path", &CalamaresPython::PythonJobInterface::workingPath )
|
||||||
|
.def_readonly( "gettext_path", &CalamaresPython::PythonJobInterface::gettextPath )
|
||||||
.def_readonly( "configuration", &CalamaresPython::PythonJobInterface::configuration )
|
.def_readonly( "configuration", &CalamaresPython::PythonJobInterface::configuration )
|
||||||
.def(
|
.def(
|
||||||
"setprogress",
|
"setprogress",
|
||||||
@ -85,7 +86,8 @@ 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" ) ) ) );
|
||||||
@ -297,6 +299,24 @@ PythonJob::exec()
|
|||||||
scriptNamespace );
|
scriptNamespace );
|
||||||
|
|
||||||
bp::object entryPoint = scriptNamespace[ "run" ];
|
bp::object entryPoint = scriptNamespace[ "run" ];
|
||||||
|
bp::object prettyNameFunc = scriptNamespace[ "pretty_name" ];
|
||||||
|
|
||||||
|
if ( !prettyNameFunc.is_none() )
|
||||||
|
{
|
||||||
|
bp::extract< std::string > prettyNameResult( prettyNameFunc() );
|
||||||
|
if ( prettyNameResult.check() )
|
||||||
|
{
|
||||||
|
m_description = QString::fromStdString( prettyNameResult() ).trimmed();
|
||||||
|
}
|
||||||
|
if ( !m_description.isEmpty() )
|
||||||
|
{
|
||||||
|
cDebug() << "Job" << prettyName() << "-pretty_name->" << m_description;
|
||||||
|
emit progress( 0 );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( m_description.isEmpty() )
|
||||||
|
{
|
||||||
bp::extract< std::string > entryPoint_doc_attr(entryPoint.attr( "__doc__" ) );
|
bp::extract< std::string > entryPoint_doc_attr(entryPoint.attr( "__doc__" ) );
|
||||||
|
|
||||||
if ( entryPoint_doc_attr.check() )
|
if ( entryPoint_doc_attr.check() )
|
||||||
@ -308,6 +328,7 @@ PythonJob::exec()
|
|||||||
cDebug() << "Job" << prettyName() << "->" << m_description;
|
cDebug() << "Job" << prettyName() << "->" << m_description;
|
||||||
emit progress( 0 );
|
emit progress( 0 );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bp::object runResult = entryPoint();
|
bp::object runResult = entryPoint();
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
/* === This file is part of Calamares - <http://github.com/calamares> ===
|
/* === This file is part of Calamares - <http://github.com/calamares> ===
|
||||||
*
|
*
|
||||||
* Copyright 2014-2016, Teo Mrnjavac <teo@kde.org>
|
* Copyright 2014-2016, Teo Mrnjavac <teo@kde.org>
|
||||||
|
* Copyright 2017, Adriaan de Groot <groot@kde.org>
|
||||||
*
|
*
|
||||||
* Calamares is free software: you can redistribute it and/or modify
|
* Calamares is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -177,10 +178,19 @@ debug( const std::string& s )
|
|||||||
PythonJobInterface::PythonJobInterface( Calamares::PythonJob* parent )
|
PythonJobInterface::PythonJobInterface( Calamares::PythonJob* parent )
|
||||||
: m_parent( parent )
|
: m_parent( parent )
|
||||||
{
|
{
|
||||||
moduleName = QDir( m_parent->m_workingPath ).dirName().toStdString();
|
auto moduleDir = QDir( m_parent->m_workingPath );
|
||||||
|
moduleName = moduleDir.dirName().toStdString();
|
||||||
prettyName = m_parent->prettyName().toStdString();
|
prettyName = m_parent->prettyName().toStdString();
|
||||||
workingPath = m_parent->m_workingPath.toStdString();
|
workingPath = m_parent->m_workingPath.toStdString();
|
||||||
configuration = CalamaresPython::variantMapToPyDict( m_parent->m_configurationMap );
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
/* === This file is part of Calamares - <http://github.com/calamares> ===
|
/* === This file is part of Calamares - <http://github.com/calamares> ===
|
||||||
*
|
*
|
||||||
* Copyright 2014-2016, Teo Mrnjavac <teo@kde.org>
|
* Copyright 2014-2016, Teo Mrnjavac <teo@kde.org>
|
||||||
|
* Copyright 2017, Adriaan de Groot <groot@kde.org>
|
||||||
*
|
*
|
||||||
* Calamares is free software: you can redistribute it and/or modify
|
* Calamares is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -60,10 +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 );
|
||||||
|
|
||||||
inline int _handle_check_target_env_call_error( int ec, const QString& cmd );
|
|
||||||
|
|
||||||
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 );
|
||||||
|
|
||||||
class PythonJobInterface
|
class PythonJobInterface
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -72,6 +73,7 @@ public:
|
|||||||
std::string moduleName;
|
std::string moduleName;
|
||||||
std::string prettyName;
|
std::string prettyName;
|
||||||
std::string workingPath;
|
std::string workingPath;
|
||||||
|
std::string gettextPath;
|
||||||
|
|
||||||
boost::python::dict configuration;
|
boost::python::dict configuration;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user