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
This commit is contained in:
Lars Gullik Bjønnes 2006-09-09 11:16:28 +00:00
parent eec4492cb4
commit 5aa348d969
7 changed files with 82 additions and 32 deletions

View File

@ -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()) { if (pimpl_->messages.get()) {
return pimpl_->messages->get(l10n); 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) { if (full_source) {
os << "% Preview source code\n\n"; os << "% Preview source code\n\n";
if (isLatex()) if (isLatex())
writeLaTeXSource(os, filePath(), runparams, true, true); writeLaTeXSource(os, filePath(), runparams, true, true);
else else
writeDocBookSource(os, fileName(), runparams, false); writeDocBookSource(os, fileName(), runparams, false);
} else { } else {
runparams.par_begin = par_begin; runparams.par_begin = par_begin;

View File

@ -20,6 +20,7 @@
#include "support/limited_stack.h" #include "support/limited_stack.h"
#include "support/types.h" #include "support/types.h"
#include "support/docstring.h"
#include <boost/scoped_ptr.hpp> #include <boost/scoped_ptr.hpp>
#include <boost/signal.hpp> #include <boost/signal.hpp>
@ -165,7 +166,7 @@ public:
/// returns the main language for the buffer (document) /// returns the main language for the buffer (document)
Language const * getLanguage() const; Language const * getLanguage() const;
/// get l10n translated to the buffers language /// 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(); int runChktex();

View File

@ -459,13 +459,15 @@ void setLabel(Buffer const & buf, ParIterator & it)
break; 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 } else if (layout->labeltype == LABEL_BIBLIO) {// ale970302
counters.step("bibitem"); counters.step("bibitem");
int number = counters.value("bibitem"); int number = counters.value("bibitem");
if (par.bibitem()) if (par.bibitem())
par.bibitem()->setCounter(number); 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... // In biblio should't be following counters but...
} else if (layout->labeltype == LABEL_SENSITIVE) { } else if (layout->labeltype == LABEL_SENSITIVE) {
// Search for the first float or wrap inset in the iterator // 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()); counters.step(fl.type());
// Doesn't work... yet. // 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 { } else {
// par->SetLayout(0); // par->SetLayout(0);
s = buf.B_(layout->labelstring()); // FIXME UNICODE
s = lyx::to_utf8(buf.B_(layout->labelstring()));
} }
par.params().labelString(s); par.params().labelString(s);
} else if (layout->labeltype == LABEL_NO_LABEL) } else if (layout->labeltype == LABEL_NO_LABEL)
par.params().labelString(string()); par.params().labelString(string());
else else
par.params().labelString(buf.B_(layout->labelstring())); // FIXME UNICODE
par.params().labelString(lyx::to_utf8(buf.B_(layout->labelstring())));
} }
} // anon namespace } // anon namespace
bool updateCurrentLabel(Buffer const & buf, bool updateCurrentLabel(Buffer const & buf,
ParIterator & it) ParIterator & it)
{ {
if (it == par_iterator_end(buf.inset())) if (it == par_iterator_end(buf.inset()))
return false; return false;
// if (it.lastpit == 0 && LyXText::isMainText()) // if (it.lastpit == 0 && LyXText::isMainText())
// return false; // return false;
switch (it->layout()->labeltype) { switch (it->layout()->labeltype) {
case LABEL_NO_LABEL: case LABEL_NO_LABEL:
case LABEL_MANUAL: case LABEL_MANUAL:
case LABEL_BIBLIO: 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) ParIterator & from, ParIterator & to)
{ {
for (ParIterator it = from; it != to; ++it) { 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) ParIterator & iter)
{ {
if (updateCurrentLabel(buf, iter)) if (updateCurrentLabel(buf, iter))
@ -565,7 +570,7 @@ void updateLabels(Buffer const & buf)
{ {
// start over the counters // start over the counters
buf.params().getLyXTextClass().counters().reset(); buf.params().getLyXTextClass().counters().reset();
ParIterator const end = par_iterator_end(buf.inset()); ParIterator const end = par_iterator_end(buf.inset());
for (ParIterator it = par_iterator_begin(buf.inset()); it != end; ++it) { 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(); LyXTextClass const & tclass = buf.params().getLyXTextClass();
string fmt = buf.B_(appendix ? layout->labelstring_appendix() // FIXME UNICODE
: layout->labelstring()); string fmt = lyx::to_utf8(buf.B_(appendix ? layout->labelstring_appendix()
: layout->labelstring()));
// handle 'inherited level parts' in 'fmt', // handle 'inherited level parts' in 'fmt',
// i.e. the stuff between '@' in '@Section@.\arabic{subsection}' // i.e. the stuff between '@' in '@Section@.\arabic{subsection}'

View File

@ -14,6 +14,7 @@
#include "gettext.h" #include "gettext.h"
#include "messages.h" #include "messages.h"
#include "support/environment.h" #include "support/environment.h"
#include "support/docstring.h"
#ifdef HAVE_LOCALE_H #ifdef HAVE_LOCALE_H
# include <locale.h> # include <locale.h>
@ -37,7 +38,7 @@ Messages & getLyXMessages()
string const _(string const & str) string const _(string const & str)
{ {
return getLyXMessages().get(str); return lyx::to_utf8(getLyXMessages().get(str));
} }

View File

@ -51,7 +51,8 @@ string const InsetFloatList::getScreenLabel(Buffer const & buf) const
FloatList const & floats = buf.params().getLyXTextClass().floats(); FloatList const & floats = buf.params().getLyXTextClass().floats();
FloatList::const_iterator it = floats[getCmdName()]; FloatList::const_iterator it = floats[getCmdName()];
if (it != floats.end()) if (it != floats.end())
return buf.B_(it->second.listName()); // FIXME UNICODE
return lyx::to_utf8(buf.B_(it->second.listName()));
else else
return _("ERROR: Nonexistent float type!"); return _("ERROR: Nonexistent float type!");
} }
@ -112,8 +113,9 @@ int InsetFloatList::latex(Buffer const & buf, ostream & os,
os << "%% unknown builtin float\n"; os << "%% unknown builtin float\n";
} }
} else { } else {
// FIXME UNICODE
os << "\\listof{" << getCmdName() << "}{" os << "\\listof{" << getCmdName() << "}{"
<< buf.B_(cit->second.listName()) << "}\n"; << lyx::to_utf8(buf.B_(cit->second.listName())) << "}\n";
} }
} else { } else {
os << "%%\\listof{" << getCmdName() << "}{" os << "%%\\listof{" << getCmdName() << "}{"

View File

@ -14,6 +14,8 @@
#include "support/filetools.h" #include "support/filetools.h"
#include "support/environment.h" #include "support/environment.h"
#include "support/package.h" #include "support/package.h"
#include "support/docstring.h"
#include "support/types.h"
#include <boost/current_function.hpp> #include <boost/current_function.hpp>
#include <boost/regex.hpp> #include <boost/regex.hpp>
@ -24,8 +26,12 @@ using lyx::support::package;
using lyx::support::getEnv; using lyx::support::getEnv;
using lyx::support::setEnv; 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 #ifdef ENABLE_NLS
@ -46,7 +52,7 @@ public:
mssg_gl(std::use_facet<std::messages<char> >(loc_gl)) mssg_gl(std::use_facet<std::messages<char> >(loc_gl))
{ {
//lyxerr << "Messages: language(" << l //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()); cat_gl = mssg_gl.open(PACKAGE, loc_gl, package().locale_dir().c_str());
@ -57,7 +63,7 @@ public:
mssg_gl.close(cat_gl); 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); return mssg_gl.get(cat_gl, 0, 0, msg);
} }
@ -100,15 +106,15 @@ public:
string::size_type i = lang_.find("."); string::size_type i = lang_.find(".");
lang_ = lang_.substr(0, i); lang_ = lang_.substr(0, i);
lyxerr[Debug::DEBUG] << BOOST_CURRENT_FUNCTION lyxerr[Debug::DEBUG] << BOOST_CURRENT_FUNCTION
<< ": language(" << lang_ << ")" << std::endl; << ": language(" << lang_ << ")" << endl;
} }
~Pimpl() {} ~Pimpl() {}
string const get(string const & m) const docstring const get(string const & m) const
{ {
if (m.empty()) if (m.empty())
return m; return lyx::from_ascii(m);
// In this order, see support/filetools.C: // In this order, see support/filetools.C:
string lang = getEnv("LC_ALL"); string lang = getEnv("LC_ALL");
@ -132,7 +138,7 @@ public:
static bool warned = false; static bool warned = false;
if (!warned && !lc_msgs) { if (!warned && !lc_msgs) {
warned = true; warned = true;
lyxerr << "Locale " << lang_ << " could not be set" << std::endl; lyxerr << "Locale " << lang_ << " could not be set" << endl;
} }
#endif #endif
// CTYPE controls what getmessage thinks what encoding the po file uses // CTYPE controls what getmessage thinks what encoding the po file uses
@ -149,9 +155,23 @@ public:
<< "Error code: " << errno << '\n' << "Error code: " << errno << '\n'
<< "Lang, mess: " << lang_ << " " << m << '\n' << "Lang, mess: " << lang_ << " " << m << '\n'
<< "Directory : " << package().locale_dir() << '\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); textdomain(PACKAGE);
#if 0
const char* msg = gettext(m.c_str()); const char* msg = gettext(m.c_str());
string translated(msg ? msg : m); string translated(msg ? msg : m);
// Some english words have different translations, depending // Some english words have different translations, depending
@ -168,6 +188,22 @@ public:
boost::smatch sub; boost::smatch sub;
if (regex_match(translated, sub, reg)) if (regex_match(translated, sub, reg))
translated = sub.str(1); 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<lyx::char_type const *>(msg);
translated = ucs4;
}
#endif
#ifdef HAVE_LC_MESSAGES #ifdef HAVE_LC_MESSAGES
setlocale(LC_MESSAGES, lang.c_str()); setlocale(LC_MESSAGES, lang.c_str());
#endif #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); return pimpl_->get(msg);
} }

View File

@ -11,6 +11,8 @@
#ifndef MESSAGES_H #ifndef MESSAGES_H
#define MESSAGES_H #define MESSAGES_H
#include "support/docstring.h"
#include <boost/scoped_ptr.hpp> #include <boost/scoped_ptr.hpp>
#include <string> #include <string>
@ -24,7 +26,7 @@ public:
/// ///
~Messages(); ~Messages();
/// ///
std::string const get(std::string const & msg) const; lyx::docstring const get(std::string const & msg) const;
private: private:
class Pimpl; class Pimpl;
boost::scoped_ptr<Pimpl> pimpl_; boost::scoped_ptr<Pimpl> pimpl_;