From 5aa348d9691cb85721d789c61935caa17ec1b84b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20Gullik=20Bj=C3=B8nnes?= Date: Sat, 9 Sep 2006 11:16:28 +0000 Subject: [PATCH] Make the l10n machinery work with ucs4. Update (as wip) callers to do manual conversion and a FIXME comment. Lots of work to do. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@14951 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/buffer.C | 10 ++++--- src/buffer.h | 3 ++- src/buffer_funcs.C | 34 +++++++++++++---------- src/gettext.C | 3 ++- src/insets/insetfloatlist.C | 6 +++-- src/messages.C | 54 ++++++++++++++++++++++++++++++------- src/messages.h | 4 ++- 7 files changed, 82 insertions(+), 32 deletions(-) diff --git a/src/buffer.C b/src/buffer.C index 19b239229e..d92deff60c 100644 --- a/src/buffer.C +++ b/src/buffer.C @@ -1385,13 +1385,15 @@ Language const * Buffer::getLanguage() const } -string const Buffer::B_(string const & l10n) const +docstring const Buffer::B_(string const & l10n) const { if (pimpl_->messages.get()) { return pimpl_->messages->get(l10n); } - return _(l10n); + // FIXME UNICODE When _() is changed to return a docstring + // the from_utf8 can be removed + return lyx::from_utf8(_(l10n)); } @@ -1599,9 +1601,9 @@ void Buffer::getSourceCode(ostream & os, lyx::pit_type par_begin, lyx::pit_type if (full_source) { os << "% Preview source code\n\n"; - if (isLatex()) + if (isLatex()) writeLaTeXSource(os, filePath(), runparams, true, true); - else + else writeDocBookSource(os, fileName(), runparams, false); } else { runparams.par_begin = par_begin; diff --git a/src/buffer.h b/src/buffer.h index d3c8d20e65..d9dbf8863c 100644 --- a/src/buffer.h +++ b/src/buffer.h @@ -20,6 +20,7 @@ #include "support/limited_stack.h" #include "support/types.h" +#include "support/docstring.h" #include #include @@ -165,7 +166,7 @@ public: /// returns the main language for the buffer (document) Language const * getLanguage() const; /// get l10n translated to the buffers language - std::string const B_(std::string const & l10n) const; + lyx::docstring const B_(std::string const & l10n) const; /// int runChktex(); diff --git a/src/buffer_funcs.C b/src/buffer_funcs.C index 22544c76dc..f796951aa2 100644 --- a/src/buffer_funcs.C +++ b/src/buffer_funcs.C @@ -459,13 +459,15 @@ void setLabel(Buffer const & buf, ParIterator & it) break; } - par.params().labelString(counters.counterLabel(buf.B_(format))); + // FIXME UNICODE + par.params().labelString(counters.counterLabel(lyx::to_utf8(buf.B_(format)))); } else if (layout->labeltype == LABEL_BIBLIO) {// ale970302 counters.step("bibitem"); int number = counters.value("bibitem"); if (par.bibitem()) par.bibitem()->setCounter(number); - par.params().labelString(buf.B_(layout->labelstring())); + // FIXME UNICODE + par.params().labelString(lyx::to_utf8(buf.B_(layout->labelstring()))); // In biblio should't be following counters but... } else if (layout->labeltype == LABEL_SENSITIVE) { // Search for the first float or wrap inset in the iterator @@ -488,33 +490,36 @@ void setLabel(Buffer const & buf, ParIterator & it) counters.step(fl.type()); // Doesn't work... yet. - s = bformat(_("%1$s #:"), buf.B_(fl.name())); + // FIXME UNICODE + s = bformat(_("%1$s #:"), lyx::to_utf8(buf.B_(fl.name()))); } else { // par->SetLayout(0); - s = buf.B_(layout->labelstring()); + // FIXME UNICODE + s = lyx::to_utf8(buf.B_(layout->labelstring())); } par.params().labelString(s); } else if (layout->labeltype == LABEL_NO_LABEL) par.params().labelString(string()); else - par.params().labelString(buf.B_(layout->labelstring())); + // FIXME UNICODE + par.params().labelString(lyx::to_utf8(buf.B_(layout->labelstring()))); } } // anon namespace -bool updateCurrentLabel(Buffer const & buf, - ParIterator & it) +bool updateCurrentLabel(Buffer const & buf, + ParIterator & it) { if (it == par_iterator_end(buf.inset())) - return false; + return false; // if (it.lastpit == 0 && LyXText::isMainText()) // return false; switch (it->layout()->labeltype) { - + case LABEL_NO_LABEL: case LABEL_MANUAL: case LABEL_BIBLIO: @@ -537,7 +542,7 @@ bool updateCurrentLabel(Buffer const & buf, } -void updateLabels(Buffer const & buf, +void updateLabels(Buffer const & buf, ParIterator & from, ParIterator & to) { for (ParIterator it = from; it != to; ++it) { @@ -551,7 +556,7 @@ void updateLabels(Buffer const & buf, } -void updateLabels(Buffer const & buf, +void updateLabels(Buffer const & buf, ParIterator & iter) { if (updateCurrentLabel(buf, iter)) @@ -565,7 +570,7 @@ void updateLabels(Buffer const & buf) { // start over the counters buf.params().getLyXTextClass().counters().reset(); - + ParIterator const end = par_iterator_end(buf.inset()); for (ParIterator it = par_iterator_begin(buf.inset()); it != end; ++it) { @@ -590,8 +595,9 @@ string expandLabel(Buffer const & buf, { LyXTextClass const & tclass = buf.params().getLyXTextClass(); - string fmt = buf.B_(appendix ? layout->labelstring_appendix() - : layout->labelstring()); + // FIXME UNICODE + string fmt = lyx::to_utf8(buf.B_(appendix ? layout->labelstring_appendix() + : layout->labelstring())); // handle 'inherited level parts' in 'fmt', // i.e. the stuff between '@' in '@Section@.\arabic{subsection}' diff --git a/src/gettext.C b/src/gettext.C index aae9bc7f5c..ea38cc88e9 100644 --- a/src/gettext.C +++ b/src/gettext.C @@ -14,6 +14,7 @@ #include "gettext.h" #include "messages.h" #include "support/environment.h" +#include "support/docstring.h" #ifdef HAVE_LOCALE_H # include @@ -37,7 +38,7 @@ Messages & getLyXMessages() string const _(string const & str) { - return getLyXMessages().get(str); + return lyx::to_utf8(getLyXMessages().get(str)); } diff --git a/src/insets/insetfloatlist.C b/src/insets/insetfloatlist.C index 14850a8347..6789066f19 100644 --- a/src/insets/insetfloatlist.C +++ b/src/insets/insetfloatlist.C @@ -51,7 +51,8 @@ string const InsetFloatList::getScreenLabel(Buffer const & buf) const FloatList const & floats = buf.params().getLyXTextClass().floats(); FloatList::const_iterator it = floats[getCmdName()]; if (it != floats.end()) - return buf.B_(it->second.listName()); + // FIXME UNICODE + return lyx::to_utf8(buf.B_(it->second.listName())); else return _("ERROR: Nonexistent float type!"); } @@ -112,8 +113,9 @@ int InsetFloatList::latex(Buffer const & buf, ostream & os, os << "%% unknown builtin float\n"; } } else { + // FIXME UNICODE os << "\\listof{" << getCmdName() << "}{" - << buf.B_(cit->second.listName()) << "}\n"; + << lyx::to_utf8(buf.B_(cit->second.listName())) << "}\n"; } } else { os << "%%\\listof{" << getCmdName() << "}{" diff --git a/src/messages.C b/src/messages.C index 0ffd990691..2b049c705e 100644 --- a/src/messages.C +++ b/src/messages.C @@ -14,6 +14,8 @@ #include "support/filetools.h" #include "support/environment.h" #include "support/package.h" +#include "support/docstring.h" +#include "support/types.h" #include #include @@ -24,8 +26,12 @@ using lyx::support::package; using lyx::support::getEnv; using lyx::support::setEnv; -using std::string; +using lyx::char_type; +using lyx::docstring; +using lyx::from_ascii; +using std::string; +using std::endl; #ifdef ENABLE_NLS @@ -46,7 +52,7 @@ public: mssg_gl(std::use_facet >(loc_gl)) { //lyxerr << "Messages: language(" << l - // << ") in dir(" << dir << ")" << std::endl; + // << ") in dir(" << dir << ")" << endl; cat_gl = mssg_gl.open(PACKAGE, loc_gl, package().locale_dir().c_str()); @@ -57,7 +63,7 @@ public: mssg_gl.close(cat_gl); } - string const get(string const & msg) const + docstring const get(string const & msg) const { return mssg_gl.get(cat_gl, 0, 0, msg); } @@ -100,15 +106,15 @@ public: string::size_type i = lang_.find("."); lang_ = lang_.substr(0, i); lyxerr[Debug::DEBUG] << BOOST_CURRENT_FUNCTION - << ": language(" << lang_ << ")" << std::endl; + << ": language(" << lang_ << ")" << endl; } ~Pimpl() {} - string const get(string const & m) const + docstring const get(string const & m) const { if (m.empty()) - return m; + return lyx::from_ascii(m); // In this order, see support/filetools.C: string lang = getEnv("LC_ALL"); @@ -132,7 +138,7 @@ public: static bool warned = false; if (!warned && !lc_msgs) { warned = true; - lyxerr << "Locale " << lang_ << " could not be set" << std::endl; + lyxerr << "Locale " << lang_ << " could not be set" << endl; } #endif // CTYPE controls what getmessage thinks what encoding the po file uses @@ -149,9 +155,23 @@ public: << "Error code: " << errno << '\n' << "Lang, mess: " << lang_ << " " << m << '\n' << "Directory : " << package().locale_dir() << '\n' - << "Rtn value : " << c << std::endl; + << "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); +#if 0 const char* msg = gettext(m.c_str()); string translated(msg ? msg : m); // Some english words have different translations, depending @@ -168,6 +188,22 @@ public: boost::smatch sub; if (regex_match(translated, sub, reg)) translated = sub.str(1); +#else + 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 << "We got a translation" << endl; + lyx::char_type const * ucs4 = reinterpret_cast(msg); + translated = ucs4; + } +#endif #ifdef HAVE_LC_MESSAGES setlocale(LC_MESSAGES, lang.c_str()); #endif @@ -211,7 +247,7 @@ Messages::~Messages() {} -string const Messages::get(string const & msg) const +docstring const Messages::get(string const & msg) const { return pimpl_->get(msg); } diff --git a/src/messages.h b/src/messages.h index f8ba53dbf0..7d8829e6f8 100644 --- a/src/messages.h +++ b/src/messages.h @@ -11,6 +11,8 @@ #ifndef MESSAGES_H #define MESSAGES_H +#include "support/docstring.h" + #include #include @@ -24,7 +26,7 @@ public: /// ~Messages(); /// - std::string const get(std::string const & msg) const; + lyx::docstring const get(std::string const & msg) const; private: class Pimpl; boost::scoped_ptr pimpl_;