First pass at setting up translation framework.
This commit is contained in:
@@ -38,7 +38,9 @@ namespace glabels
|
||||
///
|
||||
class BarcodeBackends : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Life Cycle
|
||||
/////////////////////////////////
|
||||
|
||||
@@ -101,6 +101,7 @@ set (glabels_sources
|
||||
|
||||
set (glabels_qobject_headers
|
||||
AboutDialog.h
|
||||
BarcodeBackends.h
|
||||
BarcodeMenu.h
|
||||
BarcodeMenuButton.h
|
||||
BarcodeMenuItem.h
|
||||
|
||||
@@ -28,6 +28,7 @@ namespace glabels
|
||||
namespace Config
|
||||
{
|
||||
const QString PROJECT_SOURCE_DIR = "@glabels_SOURCE_DIR@";
|
||||
const QString PROJECT_BUILD_DIR = "@glabels_BINARY_DIR@";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+5
-28
@@ -21,12 +21,12 @@
|
||||
#include "Db.h"
|
||||
|
||||
|
||||
#include <QApplication>
|
||||
#include <QtDebug>
|
||||
#include <QtGlobal>
|
||||
|
||||
#include "Config.h"
|
||||
#include "StrUtil.h"
|
||||
#include "FileUtil.h"
|
||||
#include "XmlCategoryParser.h"
|
||||
#include "XmlPaperParser.h"
|
||||
#include "XmlTemplateParser.h"
|
||||
@@ -603,32 +603,9 @@ namespace glabels
|
||||
}
|
||||
|
||||
|
||||
QDir Db::systemTemplatesDir()
|
||||
{
|
||||
QDir dir;
|
||||
|
||||
// First, try finding templates directory relative to application path
|
||||
dir.cd( QApplication::applicationDirPath() );
|
||||
if ( (dir.dirName() == "bin") &&
|
||||
dir.cdUp() && dir.cd( "share" ) && dir.cd( "glabels-qt" ) && dir.cd( "templates" ) )
|
||||
{
|
||||
return dir;
|
||||
}
|
||||
|
||||
// Next, try running out of the source directory.
|
||||
if ( dir.cd( Config::PROJECT_SOURCE_DIR ) && dir.cd( "templates" ) )
|
||||
{
|
||||
return dir;
|
||||
}
|
||||
|
||||
qFatal( "Cannot find template directory!" );
|
||||
return QDir("/");
|
||||
}
|
||||
|
||||
|
||||
void Db::readPapers()
|
||||
{
|
||||
readPapersFromDir( systemTemplatesDir() );
|
||||
readPapersFromDir( FileUtil::systemTemplatesDir() );
|
||||
}
|
||||
|
||||
|
||||
@@ -648,7 +625,7 @@ namespace glabels
|
||||
|
||||
void Db::readCategories()
|
||||
{
|
||||
readCategoriesFromDir( systemTemplatesDir() );
|
||||
readCategoriesFromDir( FileUtil::systemTemplatesDir() );
|
||||
}
|
||||
|
||||
|
||||
@@ -668,7 +645,7 @@ namespace glabels
|
||||
|
||||
void Db::readVendors()
|
||||
{
|
||||
readVendorsFromDir( systemTemplatesDir() );
|
||||
readVendorsFromDir( FileUtil::systemTemplatesDir() );
|
||||
}
|
||||
|
||||
|
||||
@@ -688,7 +665,7 @@ namespace glabels
|
||||
|
||||
void Db::readTemplates()
|
||||
{
|
||||
readTemplatesFromDir( systemTemplatesDir() );
|
||||
readTemplatesFromDir( FileUtil::systemTemplatesDir() );
|
||||
|
||||
// TODO: Read user directories
|
||||
|
||||
|
||||
+54
-9
@@ -20,23 +20,68 @@
|
||||
|
||||
#include "FileUtil.h"
|
||||
|
||||
#include <QApplication>
|
||||
|
||||
#include "Config.h"
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
namespace FileUtil
|
||||
QString FileUtil::addExtension( const QString& rawFilename, const QString& extension )
|
||||
{
|
||||
|
||||
QString addExtension( const QString& rawFilename, const QString& extension )
|
||||
if ( rawFilename.endsWith( extension ) )
|
||||
{
|
||||
if ( rawFilename.endsWith( extension ) )
|
||||
{
|
||||
return rawFilename;
|
||||
}
|
||||
|
||||
return rawFilename + extension;
|
||||
return rawFilename;
|
||||
}
|
||||
|
||||
return rawFilename + extension;
|
||||
}
|
||||
|
||||
|
||||
QDir FileUtil::systemTemplatesDir()
|
||||
{
|
||||
QDir dir;
|
||||
|
||||
// First, try finding templates directory relative to application path
|
||||
dir.cd( QApplication::applicationDirPath() );
|
||||
if ( (dir.dirName() == "bin") &&
|
||||
dir.cdUp() && dir.cd( "share" ) && dir.cd( "glabels-qt" ) && dir.cd( "templates" ) )
|
||||
{
|
||||
return dir;
|
||||
}
|
||||
|
||||
// Next, try running out of the source directory.
|
||||
if ( dir.cd( Config::PROJECT_SOURCE_DIR ) && dir.cd( "templates" ) )
|
||||
{
|
||||
return dir;
|
||||
}
|
||||
|
||||
qFatal( "Cannot locate system template directory!" );
|
||||
return QDir("/");
|
||||
}
|
||||
|
||||
|
||||
QDir FileUtil::translationsDir()
|
||||
{
|
||||
QDir dir;
|
||||
|
||||
// First, try finding translations directory relative to application path
|
||||
dir.cd( QApplication::applicationDirPath() );
|
||||
if ( (dir.dirName() == "bin") &&
|
||||
dir.cdUp() && dir.cd( "share" ) && dir.cd( "glabels-qt" ) && dir.cd( "translations" ) )
|
||||
{
|
||||
return dir;
|
||||
}
|
||||
|
||||
// Next, try running out of the source directory.
|
||||
if ( dir.cd( Config::PROJECT_BUILD_DIR ) && dir.cd( "translations" ) )
|
||||
{
|
||||
return dir;
|
||||
}
|
||||
|
||||
qFatal( "Cannot locate system template directory!" );
|
||||
return QDir("/");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
|
||||
|
||||
#include <QString>
|
||||
#include <QDir>
|
||||
|
||||
|
||||
namespace glabels
|
||||
@@ -33,6 +34,10 @@ namespace glabels
|
||||
|
||||
QString addExtension( const QString& rawFilename, const QString& extension );
|
||||
|
||||
QDir systemTemplatesDir();
|
||||
QDir userTemplatesDir();
|
||||
|
||||
QDir translationsDir();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -30,6 +30,8 @@ namespace glabels
|
||||
|
||||
class FrameCd : public Frame
|
||||
{
|
||||
Q_DECLARE_TR_FUNCTIONS(FrameCd)
|
||||
|
||||
public:
|
||||
FrameCd( const Distance& r1,
|
||||
const Distance& r2,
|
||||
|
||||
@@ -30,6 +30,7 @@ namespace glabels
|
||||
|
||||
class FrameEllipse : public Frame
|
||||
{
|
||||
Q_DECLARE_TR_FUNCTIONS(FrameEllipse)
|
||||
|
||||
public:
|
||||
FrameEllipse( const Distance& w,
|
||||
|
||||
@@ -30,6 +30,8 @@ namespace glabels
|
||||
|
||||
class FrameRect : public Frame
|
||||
{
|
||||
Q_DECLARE_TR_FUNCTIONS(FrameRect)
|
||||
|
||||
public:
|
||||
FrameRect( const Distance& w,
|
||||
const Distance& h,
|
||||
|
||||
@@ -30,6 +30,7 @@ namespace glabels
|
||||
|
||||
class FrameRound : public Frame
|
||||
{
|
||||
Q_DECLARE_TR_FUNCTIONS(FrameRound)
|
||||
|
||||
public:
|
||||
FrameRound( const Distance& r,
|
||||
|
||||
+2
-2
@@ -22,6 +22,7 @@
|
||||
|
||||
|
||||
#include <QTextStream>
|
||||
#include <QCoreApplication>
|
||||
#include <QtDebug>
|
||||
|
||||
|
||||
@@ -192,7 +193,6 @@ namespace glabels
|
||||
{
|
||||
init();
|
||||
|
||||
// TODO: are translations done in a compatable way, so that we can use "_name" attributes?
|
||||
QString i18nString = node.attribute( QString("_").append(name), "" );
|
||||
|
||||
if ( i18nString == "" )
|
||||
@@ -200,7 +200,7 @@ namespace glabels
|
||||
return node.attribute( name, default_value );
|
||||
}
|
||||
|
||||
return i18nString;
|
||||
return QCoreApplication::translate( "XmlStrings", i18nString.toUtf8().constData() );
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -20,7 +20,11 @@
|
||||
|
||||
|
||||
#include <QApplication>
|
||||
#include <QLocale>
|
||||
#include <QTranslator>
|
||||
#include <QtDebug>
|
||||
|
||||
#include "FileUtil.h"
|
||||
#include "Db.h"
|
||||
#include "MainWindow.h"
|
||||
#include "Settings.h"
|
||||
@@ -36,19 +40,39 @@ int main( int argc, char **argv )
|
||||
QCoreApplication::setOrganizationDomain( "glabels.org" );
|
||||
QCoreApplication::setApplicationName( "glabels-qt" );
|
||||
|
||||
//
|
||||
// Setup translators
|
||||
//
|
||||
QLocale locale = QLocale::system();
|
||||
QString translationsDir = glabels::FileUtil::translationsDir().canonicalPath();
|
||||
|
||||
QTranslator glabelsTranslator;
|
||||
if ( glabelsTranslator.load( locale, "glabels", "_", translationsDir ) )
|
||||
{
|
||||
app.installTranslator(&glabelsTranslator);
|
||||
}
|
||||
|
||||
QTranslator templatesTranslator;
|
||||
if ( templatesTranslator.load( locale, "templates", "_", translationsDir ) )
|
||||
{
|
||||
app.installTranslator(&templatesTranslator);
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Initialize subsystems
|
||||
//
|
||||
glabels::Settings::init();
|
||||
glabels::Db::init();
|
||||
glabels::merge::Factory::init();
|
||||
////// TEMPORARY TESTING ////////
|
||||
#if 0
|
||||
glabels::Db::printKnownPapers();
|
||||
glabels::Db::printKnownCategories();
|
||||
glabels::Db::printKnownVendors();
|
||||
glabels::Db::printKnownTemplates();
|
||||
#endif
|
||||
/////////////////////////////////
|
||||
|
||||
|
||||
/// @TODO open file(s) from command line if present, otherwise start wizard
|
||||
|
||||
|
||||
//
|
||||
// Launch main window
|
||||
//
|
||||
glabels::MainWindow mainWindow;
|
||||
mainWindow.show();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user