more messages work

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@6864 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Lars Gullik Bjønnes 2003-04-27 22:11:45 +00:00
parent d6546c2bf4
commit e2b65dec0c
8 changed files with 68 additions and 48 deletions

View File

@ -1,3 +1,24 @@
2003-04-28 Lars Gullik Bjønnes <larsbj@gullik.net>
* messages.C (getLocaleDir): singleton generation function
(Pimpl): use it.
(Messages): add a default constructor.
* main.C (main): do not setup localedir here, do not call
gettext_init.
* gettext.C (_): use it.
(gettext_init): delete funciton
2003-04-27 Lars Gullik Bjønnes <larsbj@gullik.net>
* gettext.C (getLyXMessages): new singleton generating function.
* buffer.C (updateDocLang): adjust
* Makefile.am (messages.o): add target
(main.o): remove target
2003-04-27 John Levon <levon@movementarian.org>
* bufferlist.C:
@ -14,7 +35,7 @@
* lyxfunc.C: don't enable tabular-feature when there's
just any locking inset
2003-04-26 John Levon <levon@movementarian.org>
* bufferlist.C: re-add Cancel to buffer close question

View File

@ -244,8 +244,8 @@ lyx_main.o: lyx_main.C lyx_main.h config.h version.h \
$(CXXCOMPILE) -DLYX_DIR=\"$(pkgdatadir)\" \
-DTOP_SRCDIR=\"$(top_srcdir)\" -c $(top_srcdir)/src/lyx_main.C
main.o: main.C config.h lyx_main.h gettext.h LString.h support/filetools.h support/os.h
$(CXXCOMPILE) -DLOCALEDIR=\"$(localedir)\" -c $(top_srcdir)/src/main.C
messages.o: messages.C messages.h config.h LString.h support/filetools.h
$(CXXCOMPILE) -DLOCALEDIR=\"$(localedir)\" -c $(top_srcdir)/src/messages.C
dist-hook:
cd $(distdir) ; rm -rf `find cheaders -name \*CVS\*`

View File

@ -2227,7 +2227,7 @@ void Buffer::changeLanguage(Language const * from, Language const * to)
void Buffer::updateDocLang(Language const * nlang)
{
messages_.reset(new Messages(nlang->code(), "/usr/local/share/locale"));
messages_.reset(new Messages(nlang->code()));
}

View File

@ -22,38 +22,25 @@
namespace {
boost::scoped_ptr<Messages> lyx_messages;
Messages & getLyXMessages()
{
static Messages lyx_messages;
return lyx_messages;
}
} // anon namespace
char const * _(char const * str)
{
// This breaks pretty much immediately
// lyx::Assert(str && str[0]);
if (!lyx_messages.get())
return str;
return lyx_messages->get(str).c_str();
return getLyXMessages().get(str).c_str();
}
string const _(string const & str)
{
// This breaks pretty much immediately
// lyx::Assert(!str.empty());
if (!lyx_messages.get())
return str;
return lyx_messages->get(str);
}
void gettext_init(string const & localedir)
{
lyx_messages.reset(new Messages("", localedir));
return getLyXMessages().get(str);
}

View File

@ -50,7 +50,5 @@ string const _(string const &);
///
void locale_init();
///
void gettext_init(string const & localedir);
#endif

View File

@ -11,23 +11,14 @@
#include "lyx_main.h"
#include "gettext.h"
#include "LString.h"
#include "support/filetools.h"
#include "support/os.h"
int main(int argc, char * argv[])
{
os::init(&argc, &argv);
// lyx_localedir is used by gettext_init() is we have
// i18n support built-in
string lyx_localedir = GetEnvPath("LYX_LOCALEDIR");
if (lyx_localedir.empty())
lyx_localedir = LOCALEDIR;
// initialize for internationalized version *EK*
locale_init();
gettext_init(lyx_localedir);
LyX lyx(argc, argv);
return 0;

View File

@ -11,10 +11,27 @@
#include "messages.h"
#include "debug.h"
#include "support/filetools.h"
#ifdef ENABLE_NLS
namespace {
string const & getLocaleDir()
{
static string locale_dir;
if (locale_dir.empty()) {
locale_dir = GetEnvPath("LYX_LOCALEDIR");
if (locale_dir.empty())
locale_dir = LOCALEDIR;
}
return locale_dir;
}
} // anon namespace
#if 0
#include <locale>
@ -25,15 +42,15 @@ class Messages::Pimpl {
public:
typedef std::messages<char>::catalog catalog;
Pimpl(string const & l, string const & dir)
: lang_(l), localedir_(dir),
Pimpl(string const & l)
: lang_(l),
loc_gl(lang_.c_str()),
mssg_gl(std::use_facet<std::messages<char> >(loc_gl))
{
//lyxerr << "Messages: language(" << l
// << ") in dir(" << dir << ")" << std::endl;
cat_gl = mssg_gl.open(PACKAGE, loc_gl, localedir_.c_str());
cat_gl = mssg_gl.open(PACKAGE, loc_gl, getLocaleDir().c_str());
}
@ -50,8 +67,6 @@ private:
///
string lang_;
///
string localedir_;
///
std::locale loc_gl;
///
std::messages<char> const & mssg_gl;
@ -73,13 +88,13 @@ private:
// This is a more traditional variant.
class Messages::Pimpl {
public:
Pimpl(string const & l, string const & dir)
: lang_(l), localedir_(dir)
Pimpl(string const & l)
: lang_(l)
{
//lyxerr << "Messages: language(" << l
// << ") in dir(" << dir << ")" << std::endl;
bindtextdomain(PACKAGE, localedir_.c_str());
bindtextdomain(PACKAGE, getLocaleDir().c_str());
textdomain(PACKAGE);
}
@ -108,7 +123,7 @@ private:
// This is the dummy variant.
class Messages::Pimpl {
public:
Pimpl(string const &, string const &) {}
Pimpl(string const &) {}
~Pimpl() {}
@ -119,8 +134,14 @@ public:
};
#endif
Messages::Messages(string const & l, string const & dir)
: pimpl_(new Pimpl(l, dir))
Messages::Messages()
: pimpl_(new Pimpl(""))
{}
Messages::Messages(string const & l)
: pimpl_(new Pimpl(l))
{}

View File

@ -19,7 +19,9 @@
class Messages {
public:
///
Messages(string const & l, string const & dir);
Messages();
///
Messages(string const & l);
///
~Messages();
///