Am Freitag, 3. November 2006 21:01 schrieb Bo Peng: > Therefore, tex2lyx uses the no-translation _(). and > support/package.C.in uses a different gettext.h with translation. > Then, there is a link problem. > > I do not have time to trace why gcc passes and the problem can be > fixed by using tex2lyx/gettext.h for packages.C.
I don't understand at all why gcc (or rather the linker) does not complain. BTW src/client has the same problem. > However, I see no > reason for a separate _() function for tex2lyx and propose that we > remove tex2lyx/gettext.* and use the src/gettext.*. It is not that easy unfortunately. Removing tex2lyx/gettext.C does only make sense if we enable real translations in tex2lyx at the same time: include the files in the po machinery, and either install a separate tex2lyx .mo file or make it use the one from LyX. You can see in the client that that is not trivial, and requires some extra code anyway. Therefore I propose to only get rid of the extra headers for now. Future interface changes will then cause a compiler error. The attached patch does this, and fixes the interface. It goes in later today unless I get objections. Georg
Index: src/gettext.C =================================================================== --- src/gettext.C (Revision 15726) +++ src/gettext.C (Arbeitskopie) @@ -14,7 +14,6 @@ #include "gettext.h" #include "messages.h" #include "support/environment.h" -#include "support/docstring.h" namespace lyx { Index: src/gettext.h =================================================================== --- src/gettext.h (Revision 15726) +++ src/gettext.h (Arbeitskopie) @@ -15,8 +15,6 @@ #include "support/docstring.h" -#include <string> - namespace lyx { Index: src/client/gettext.C =================================================================== --- src/client/gettext.C (Revision 15726) +++ src/client/gettext.C (Arbeitskopie) @@ -37,7 +37,7 @@ Messages & getLyXMessages() } // anon namespace -string const _(string const & str) +docstring const _(string const & str) { return getLyXMessages().get(str); } Index: src/client/debug.C =================================================================== --- src/client/debug.C (Revision 15726) +++ src/client/debug.C (Arbeitskopie) @@ -88,10 +88,10 @@ void lyx_debug_trait::showLevel(ostream && errorTags[i].level & level) { // avoid _(...) re-entrance problem // FIXME: should we use _() from gettext.h here? - string const s = _(errorTags[i].desc); - os << lyx::to_utf8(bformat(lyx::from_utf8(_("Debugging `%1$s' (%2$s)")), + lyx::docstring const s = _(errorTags[i].desc); + os << lyx::to_utf8(bformat(_("Debugging `%1$s' (%2$s)"), lyx::from_utf8(errorTags[i].name), - lyx::from_utf8(s))) + s)) << '\n'; } } @@ -104,7 +104,7 @@ void lyx_debug_trait::showTags(ostream & for (int i = 0; i < numErrorTags ; ++i) os << setw(7) << static_cast<unsigned int>(errorTags[i].level) << setw(10) << errorTags[i].name - << " " << _(errorTags[i].desc) << '\n'; + << " " << lyx::to_utf8(_(errorTags[i].desc)) << '\n'; os.flush(); } Index: src/client/messages.C =================================================================== --- src/client/messages.C (Revision 15726) +++ src/client/messages.C (Arbeitskopie) @@ -17,6 +17,7 @@ namespace lyx { using lyx::support::package; +using std::endl; using std::string; @@ -90,21 +91,63 @@ public: ~Pimpl() {} - string const get(string const & m) const + docstring const get(string const & m) const { if (m.empty()) - return m; + return from_ascii(m); - char * old = strdup(setlocale(LC_ALL, 0)); + char * o = setlocale(LC_ALL, 0); + string old; + if (o) + old = o; char * n = setlocale(LC_ALL, lang_.c_str()); - bindtextdomain(PACKAGE, package().locale_dir().c_str()); + if (!n) + // If we are unable to honour the request we just + // return what we got in. + return from_ascii(m); + errno = 0; + char const * c = bindtextdomain(PACKAGE, package().locale_dir().c_str()); + int e = errno; + if (e) { + lyxerr[Debug::DEBUG] + << BOOST_CURRENT_FUNCTION << '\n' + << "Error code: " << errno << '\n' + << "Lang, mess: " << lang_ << " " << m << '\n' + << "Directory : " << package().locale_dir() << '\n' + << "Rtn value : " << c << endl; + } + +#ifdef WORDS_BIGENDIAN + static const char * codeset = "UCS-4BE"; +#else + static const char * codeset = "UCS-4LE"; +#endif + if (!bind_textdomain_codeset(PACKAGE, codeset)) { + lyxerr[Debug::DEBUG] + << BOOST_CURRENT_FUNCTION << '\n' + << "Error code: " << errno << '\n' + << "Codeset : " << codeset << '\n' + << endl; + } + textdomain(PACKAGE); - const char* msg = gettext(m.c_str()); - setlocale(LC_ALL, old); - free(old); - // If we are unable to honour the request we just - // return what we got in. - return (!n ? m : string(msg)); + + char const * tmp = m.c_str(); + char const * msg = gettext(tmp); + docstring translated; + if (!msg) { + lyxerr << "Undefined result from gettext" << endl; + translated = from_ascii(tmp); + } else if (msg == tmp) { + //lyxerr << "Same as entered returned" << endl; + translated = from_ascii(tmp); + } else { + lyxerr[Debug::DEBUG] << "We got a translation" << endl; + char_type const * ucs4 = reinterpret_cast<char_type const *>(msg); + translated = ucs4; + } + setlocale(LC_ALL, old.c_str()); + return translated; } private: /// @@ -120,7 +163,7 @@ public: ~Pimpl() {} - string const get(string const & m) const + docstring const get(string const & m) const { return m; } @@ -143,7 +186,7 @@ Messages::~Messages() {} -string const Messages::get(string const & msg) const +docstring const Messages::get(string const & msg) const { return pimpl_->get(msg); } Index: src/client/Makefile.am =================================================================== --- src/client/Makefile.am (Revision 15726) +++ src/client/Makefile.am (Arbeitskopie) @@ -24,7 +24,6 @@ lyxclient_SOURCES = \ debug.C \ debug.h \ gettext.C \ - gettext.h \ messages.C \ messages.h Index: src/client/gettext.h =================================================================== --- src/client/gettext.h (Revision 15726) +++ src/client/gettext.h (Arbeitskopie) @@ -1,70 +0,0 @@ -// -*- C++ -*- -/** - * \file src/gettext.h - * This file is part of LyX, the document processor. - * Licence details can be found in the file COPYING. - * - * \author Lars Gullik Bjønnes - * \author Jean-Marc Lasgouttes - * - * Full author contact details are available in file CREDITS. - */ - -#ifndef GETTEXT_H -#define GETTEXT_H - -#include <string> - - -namespace lyx { - -/* - * Native Language Support - * - * The general idea is that any string that should be translated is handled - * as follows: - * _("string") - * - * Static strings are special, obviously and must be flagged as follows: - * static str = N_("string"); - * - * And wherever they are used: - * _(str) - * - * Every file where there are strings needs: - * #include "gettext.h" - * - * Remember to mention each of these files in "po/POFILES.in" - * - * The main() needs a locale_init() and a gettext_init() in the beginning. - */ - -/* - * General translation notes: - * Commands/options are not translated - * Debug messages are not translated - * Panic/fatal (that should not happen) messages need not be translated - */ - - -//#ifdef ENABLE_NLS - -/// -std::string const _(std::string const &); - -//#else // ENABLE_NLS - -/// -//# define _(str) (str) - -//#endif - -# define N_(str) (str) // for detecting static strings - -/// -void locale_init(); - - -} // namespace lyx - -#endif Index: src/client/messages.h =================================================================== --- src/client/messages.h (Revision 15726) +++ src/client/messages.h (Arbeitskopie) @@ -11,8 +11,9 @@ #ifndef MESSAGES_H #define MESSAGES_H +#include "support/docstring.h" + #include <boost/scoped_ptr.hpp> -#include <string> namespace lyx { @@ -27,7 +28,7 @@ public: /// ~Messages(); /// - std::string const get(std::string const & msg) const; + docstring const get(std::string const & msg) const; private: class Pimpl; boost::scoped_ptr<Pimpl> pimpl_; Index: src/tex2lyx/gettext.C =================================================================== --- src/tex2lyx/gettext.C (Revision 15726) +++ src/tex2lyx/gettext.C (Arbeitskopie) @@ -16,12 +16,10 @@ namespace lyx { -using std::string; - -string const _(string const & str) +docstring const _(std::string const & str) { - return str; + return from_ascii(str); } Index: src/tex2lyx/Makefile.am =================================================================== --- src/tex2lyx/Makefile.am (Revision 15726) +++ src/tex2lyx/Makefile.am (Arbeitskopie) @@ -42,7 +42,6 @@ tex2lyx_SOURCES = \ context.C \ context.h \ gettext.C \ - gettext.h \ lengthcommon.C \ lyxfont.C \ lyxfont.h \ Index: src/tex2lyx/gettext.h =================================================================== --- src/tex2lyx/gettext.h (Revision 15726) +++ src/tex2lyx/gettext.h (Arbeitskopie) @@ -1,33 +0,0 @@ -// -*- C++ -*- -/** - * \file tex2lyx/gettext.h - * This file is part of LyX, the document processor. - * Licence details can be found in the file COPYING. - * - * \author Lars Gullik Bjønnes - * \author Jean-Marc Lasgouttes - * - * Full author contact details are available in file CREDITS. - */ -#ifndef GETTEXT_H -#define GETTEXT_H - -#include <string> - - -namespace lyx { - - -/// -std::string const _(std::string const &); - -/// for detecting static strings -#define N_(str) (str) - -/// -void locale_init(); - - -} // namespace lyx - -#endif Index: po/POTFILES.in =================================================================== --- po/POTFILES.in (Revision 15726) +++ po/POTFILES.in (Arbeitskopie) @@ -1,4 +1,3 @@ -src/BranchList.h src/BufferView.C src/Chktex.C src/CutAndPaste.C @@ -12,7 +11,6 @@ src/bufferlist.C src/bufferparams.C src/bufferview_funcs.C src/client/debug.C -src/client/gettext.h src/converter.C src/debug.C src/exporter.C Index: development/scons/scons_manifest.py =================================================================== --- development/scons/scons_manifest.py (Revision 15726) +++ development/scons/scons_manifest.py (Arbeitskopie) @@ -972,7 +972,6 @@ src_frontends_qt4_files = Split(''' src_client_header_files = Split(''' debug.h - gettext.h messages.h ''') @@ -989,7 +988,6 @@ src_client_files = Split(''' src_tex2lyx_header_files = Split(''' Spacing.h context.h - gettext.h lyxfont.h messages.h tex2lyx.h