mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-22 13:18:28 +00:00
[the "translation" patch series] Part 4: translating the LyX menu on the mac
* development/MacOSX/Makefile.am: when installing, create bogus language directories to allow translation through Qt. * src/frontends/qt4/GuiApplication.cpp (MenuTranslator): new class, redirects some Qt translation requests to gettext. (GuiApplication): install the MenuTranslator. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@19354 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
b708d5c53b
commit
951701394e
@ -1,5 +1,7 @@
|
||||
include $(top_srcdir)/config/common.am
|
||||
|
||||
LINGUAS = $(srcdir)/../../po/LINGUAS
|
||||
|
||||
SUBDIRS = spotlight
|
||||
|
||||
bundledir = ${prefix}/Contents
|
||||
@ -9,3 +11,9 @@ dist_bin_SCRIPTS = lyxeditor
|
||||
|
||||
dist_pkgdata_DATA = COPYING LyXapp.icns LyX.icns lyxrc.dist
|
||||
|
||||
|
||||
install-data-hook:
|
||||
LINGUAS_=`sed -e "/^#/d" -e "s/#.*//" $(LINGUAS)`; \
|
||||
for f in $$LINGUAS_ ; do \
|
||||
$(MKDIR_P) $(pkgdatadir)/$$f.lproj ; \
|
||||
done
|
||||
|
@ -31,6 +31,7 @@
|
||||
#include "Color.h"
|
||||
#include "debug.h"
|
||||
#include "FuncRequest.h"
|
||||
#include "gettext.h"
|
||||
#include "LyX.h"
|
||||
#include "LyXFunc.h"
|
||||
#include "LyXRC.h"
|
||||
@ -119,9 +120,9 @@ GuiApplication::GuiApplication(int & argc, char ** argv)
|
||||
if (qt_trans_.load(language_name,
|
||||
QLibraryInfo::location(QLibraryInfo::TranslationsPath)))
|
||||
{
|
||||
qApp->installTranslator(&qt_trans_);
|
||||
installTranslator(&qt_trans_);
|
||||
// even if the language calls for RtL, don't do that
|
||||
qApp->setLayoutDirection(Qt::LeftToRight);
|
||||
setLayoutDirection(Qt::LeftToRight);
|
||||
LYXERR(Debug::GUI)
|
||||
<< "Successfully installed Qt translations for locale "
|
||||
<< fromqstr(language_name) << std::endl;
|
||||
@ -130,6 +131,11 @@ GuiApplication::GuiApplication(int & argc, char ** argv)
|
||||
<< "Could not find Qt translations for locale "
|
||||
<< fromqstr(language_name) << std::endl;
|
||||
|
||||
#ifdef Q_WS_MACX
|
||||
// This allows to translate the strings that appear in the LyX menu.
|
||||
addMenuTranslator();
|
||||
#endif
|
||||
|
||||
using namespace lyx::graphics;
|
||||
|
||||
Image::newImage = boost::bind(&QLImage::newImage);
|
||||
@ -343,6 +349,38 @@ bool GuiApplication::x11EventFilter(XEvent * xev)
|
||||
#endif
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// Mac specific stuff goes here...
|
||||
|
||||
class MenuTranslator : public QTranslator {
|
||||
public:
|
||||
virtual ~MenuTranslator() {};
|
||||
virtual QString translate(const char * context,
|
||||
const char * sourceText,
|
||||
const char * comment = 0) const;
|
||||
};
|
||||
|
||||
|
||||
QString MenuTranslator::translate(const char * /*context*/,
|
||||
const char * sourceText,
|
||||
const char *) const
|
||||
{
|
||||
string const s = sourceText;
|
||||
if (s == N_("About %1") || s == N_("Preferences")
|
||||
|| s == N_("Reconfigure") || s == N_("Quit %1"))
|
||||
return qt_(s);
|
||||
else
|
||||
return QString();
|
||||
}
|
||||
|
||||
|
||||
void GuiApplication::addMenuTranslator()
|
||||
{
|
||||
menu_trans_.reset(new MenuTranslator());
|
||||
installTranslator(menu_trans_.get());
|
||||
}
|
||||
|
||||
|
||||
} // namespace frontend
|
||||
} // namespace lyx
|
||||
|
||||
|
@ -21,6 +21,8 @@
|
||||
|
||||
#include "frontends/Application.h"
|
||||
|
||||
#include <boost/scoped_ptr.hpp>
|
||||
|
||||
#include <QApplication>
|
||||
#include <QTranslator>
|
||||
|
||||
@ -32,6 +34,7 @@ class socket_callback;
|
||||
namespace frontend {
|
||||
|
||||
class GuiWorkArea;
|
||||
class MenuTranslator;
|
||||
|
||||
/// The Qt main application class
|
||||
/**
|
||||
@ -107,6 +110,11 @@ public:
|
||||
bool x11EventFilter (XEvent * ev);
|
||||
#endif
|
||||
|
||||
/// A translator suitable for the entries in the LyX menu.
|
||||
/// Only needed with Qt/Mac.
|
||||
void addMenuTranslator();
|
||||
///
|
||||
boost::scoped_ptr<MenuTranslator> menu_trans_;
|
||||
}; // GuiApplication
|
||||
|
||||
extern GuiApplication * guiApp;
|
||||
|
Loading…
Reference in New Issue
Block a user