Skip to content
Snippets Groups Projects
Commit 89c33e3d authored by Julien Malik's avatar Julien Malik
Browse files

ENH: remove references to CMAKE_INSTALL_PREFIX from sources. load translation...

ENH: remove references to CMAKE_INSTALL_PREFIX from sources. load translation with relative dir strategy
parent 95e94b82
No related branches found
No related tags found
No related merge requests found
...@@ -78,62 +78,76 @@ I18nApplication ...@@ -78,62 +78,76 @@ I18nApplication
// //
// 2. Choose i18n path between build dir and install dir. // 2. Choose i18n path between build dir and install dir.
// Begin from the executable path
QDir bin_dir( QDir::cleanPath(QCoreApplication::applicationDirPath()) );
qDebug() << "Executable dir : " << bin_dir;
// Go up in the directory hierarchy until we have a candidate install prefix
bool prefixFound = false;
QDir prefix( bin_dir );
while ( prefix.cdUp() )
{
if ( QDir(prefix).cd(Monteverdi2_INSTALL_BIN_DIR) )
{
prefixFound = true;
break;
}
}
if (prefixFound)
{
qDebug() << "Candidate install prefix found : " << prefix;
}
else
{
QString message( tr( "Unable to locate translation files" ) );
qDebug() << message;
QMessageBox::critical( NULL, tr( "Critical error" ), message );
return;
}
QDir i18n_dir; QDir i18n_dir;
QDir bin_dir( QDir::cleanPath( QCoreApplication::applicationDirPath() ) );
QDir build_i18n_dir( bin_dir ); // At this point the candidate install prefix can also be the build dir root
if ( prefix.exists( Monteverdi2_CONFIGURE_FILE )
// If build dir is identified... && prefix.exists("i18n") )
if( (build_i18n_dir.exists( "../i18n" )
&& build_i18n_dir.cd( "../i18n" )
&& build_i18n_dir.exists( "../" Monteverdi2_CONFIGURE_FILE ))
|| (build_i18n_dir.exists( "../../i18n" )
&& build_i18n_dir.cd( "../../i18n" )
&& build_i18n_dir.exists( "../" Monteverdi2_CONFIGURE_FILE )) )
{ {
m_IsRunningFromBuildDir = true; m_IsRunningFromBuildDir = true;
// ...use build dir as prioritary load path for translation. // Report found build dir root
i18n_dir = build_i18n_dir; qDebug() << tr( "Running from build directory '%1'." ).arg( prefix.path() );
// TODO: Use log system to trace message. // Go into the i18n dir (it exists we just checked for it)
qDebug() i18n_dir = prefix;
<< tr( "Running from build directory '%1'." ).arg( bin_dir.path() ); i18n_dir.cd("i18n");
qDebug() << tr( "Using translation dir '%1'." ).arg( i18n_dir.path() );
} }
// Otherwise...
else else
{ {
m_IsRunningFromBuildDir = false; m_IsRunningFromBuildDir = false;
QDir install_i18n_dir( QDir::cleanPath( Monteverdi2_INSTALL_DATA_I18N_DIR ) ); // Report found install prefix
// ...if install data dir is identified qDebug() << tr( "Running from install directory '%1'." ).arg( prefix.path() );
if( install_i18n_dir.exists() )
// Go into the i18n dir configured at cmake-time
i18n_dir = prefix;
if (i18n_dir.cd(Monteverdi2_INSTALL_DATA_I18N_DIR))
{ {
// ...use install data dir as load path for translation. qDebug() << tr( "Using translation dir '%1'." ).arg( i18n_dir.path() );
i18n_dir = install_i18n_dir;
// TODO: Use log system to trace message.
qDebug()
<< tr( "Running from install directory '%1'." ).arg( Monteverdi2_INSTALL_BIN_DIR );
} }
// Otherwise
else else
{ {
QString message( QString message( tr( "Failed to access translation-files directory '%1'" )
tr( "Failed to access translation-files directory '%1'." ) .arg(QDir::cleanPath(prefix.path() + Monteverdi2_INSTALL_DATA_I18N_DIR)) );
.arg( install_i18n_dir.path() )
);
// TODO: Use log system to trace error while loading locale translation file.
qDebug() << message; qDebug() << message;
QMessageBox::critical( NULL, tr( "Critical error" ), message );
// TODO: morph into better HMI design.
QMessageBox::critical( NULL, tr( "Critical error!" ), message );
return; return;
} }
} }
// //
// 3.1 Stack Qt translator. // 3.1 Stack Qt translator.
LoadAndInstallTranslator( LoadAndInstallTranslator(
......
...@@ -37,11 +37,10 @@ ...@@ -37,11 +37,10 @@
// //
// Directories // Directories
#define Monteverdi2_INSTALL_PREFIX "@CMAKE_INSTALL_PREFIX@" #define Monteverdi2_INSTALL_BIN_DIR "@Monteverdi2_INSTALL_BIN_DIR@"
#define Monteverdi2_INSTALL_BIN_DIR "@CMAKE_INSTALL_PREFIX@/@Monteverdi2_INSTALL_BIN_DIR@" #define Monteverdi2_INSTALL_INCLUDE_DIR "@Monteverdi2_INSTALL_INCLUDE_DIR@"
#define Monteverdi2_INSTALL_INCLUDE_DIR "@CMAKE_INSTALL_PREFIX@/@Monteverdi2_INSTALL_INCLUDE_DIR@" #define Monteverdi2_INSTALL_LIB_DIR "@Monteverdi2_INSTALL_LIB_DIR@"
#define Monteverdi2_INSTALL_LIB_DIR "@CMAKE_INSTALL_PREFIX@/@Monteverdi2_INSTALL_LIB_DIR@" #define Monteverdi2_INSTALL_DATA_DIR "@Monteverdi2_INSTALL_DATA_DIR@"
#define Monteverdi2_INSTALL_DATA_DIR "@CMAKE_INSTALL_PREFIX@/@Monteverdi2_INSTALL_DATA_DIR@"
// //
// Sub-directories // Sub-directories
#define Monteverdi2_INSTALL_DATA_I18N_DIR Monteverdi2_INSTALL_DATA_DIR "/i18n" #define Monteverdi2_INSTALL_DATA_I18N_DIR Monteverdi2_INSTALL_DATA_DIR "/i18n"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment