Jean-Pierre Chrétien wrote:
Abdelrazak Younes <[EMAIL PROTECTED]> writes:
1) provide a python script that converts the layout as good as possible:
  Théorème  -> Theoreme
  Liste_à_puce -> Liste_a_puce

The problem is that it could be done easily for French but maybe not for other languages. Second problem is that I am not sure we have a lyx2lyx equivalent for layoouts, do we?

2) Accept the layout field as is and do not try to translate them.

Given the burden of gettext management, this would clearly be better,

I've implemented that already, see attached patch. I agree this is better to the end-user who doesn't care if his styles are not translated. Especially if these styles are not meant to be distributed outside his classroom for example.

but what about encoding ? From 1.5, the reference encoding is Unicode,
so that style naming should be in Unicode in the layout file, and
converted to the locale to display, like any other menu.

Yes, all layout files need to be encoded in UTF-8 otherwise my patch will not work.


Maybe some script to ease gettext management would be better, to keep
this in the global translation flow.

Too difficult IMHO.

Abdel.

Index: src/BufferView.h
===================================================================
--- src/BufferView.h    (revision 19003)
+++ src/BufferView.h    (working copy)
@@ -242,7 +242,7 @@
                std::string data)> updateDialog;
 
        /// This signal is emitted when the layout at the cursor is changed.
-       boost::signal<void(std::string layout)> layoutChanged;
+       boost::signal<void(docstring layout)> layoutChanged;
 
 private:
        ///
Index: src/CutAndPaste.cpp
===================================================================
--- src/CutAndPaste.cpp (revision 19003)
+++ src/CutAndPaste.cpp (working copy)
@@ -423,7 +423,7 @@
        // layouts
        ParIterator end = par_iterator_end(in);
        for (ParIterator it = par_iterator_begin(in); it != end; ++it) {
-               string const name = it->layout()->name();
+               docstring const name = it->layout()->name();
                bool hasLayout = tclass2.hasLayout(name);
 
                if (hasLayout)
@@ -435,7 +435,7 @@
                        docstring const s = bformat(
                                                 _("Layout had to be changed 
from\n%1$s to %2$s\n"
                                                "because of class conversion 
from\n%3$s to %4$s"),
-                        from_utf8(name), from_utf8(it->layout()->name()),
+                        name, it->layout()->name(),
                         from_utf8(tclass1.name()), from_utf8(tclass2.name()));
                        // To warn the user that something had to be done.
                        errorlist.push_back(ErrorItem(_("Changed Layout"), s,
Index: src/factory.cpp
===================================================================
--- src/factory.cpp     (revision 19003)
+++ src/factory.cpp     (working copy)
@@ -228,7 +228,7 @@
                        return new 
InsetTOC(InsetCommandParams("tableofcontents"));
 
                case LFUN_ENVIRONMENT_INSERT:
-                       return new InsetEnvironment(params, 
to_utf8(cmd.argument()));
+                       return new InsetEnvironment(params, cmd.argument());
 
 #if 0
                case LFUN_LIST_INSERT:
@@ -491,7 +491,7 @@
                        inset.reset(new InsetInclude(p));
                } else if (tmptok == "Environment") {
                        lex.next();
-                       inset.reset(new InsetEnvironment(buf.params(), 
lex.getString()));
+                       inset.reset(new InsetEnvironment(buf.params(), 
lex.getDocString()));
                } else if (tmptok == "ERT") {
                        inset.reset(new InsetERT(buf.params()));
                } else if (tmptok == "listings") {
Index: src/frontends/LyXView.cpp
===================================================================
--- src/frontends/LyXView.cpp   (revision 19003)
+++ src/frontends/LyXView.cpp   (working copy)
@@ -68,7 +68,7 @@
 
 using lyx::frontend::ControlCommandBuffer;
 
-string current_layout;
+docstring current_layout;
 
 
 LyXView::LyXView(int id)
@@ -462,7 +462,7 @@
        }
 
        BOOST_ASSERT(work_area_);
-       string const & layout = work_area_->bufferView().cursor().
+       docstring const & layout = work_area_->bufferView().cursor().
                innerParagraph().layout()->name();
 
        if (layout != current_layout) {
Index: src/frontends/qt4/QDocument.cpp
===================================================================
--- src/frontends/qt4/QDocument.cpp     (revision 19003)
+++ src/frontends/qt4/QDocument.cpp     (working copy)
@@ -852,7 +852,7 @@
                if (toclevel != Layout::NOT_IN_TOC
                    && (*cit)->labeltype == LABEL_COUNTER) {
                        item = new QTreeWidgetItem(numberingModule->tocTW);
-                       item->setText(0, qt_((*cit)->name()));
+                       item->setText(0, 
toqstr(translateIfPossible((*cit)->name())));
                        item->setText(1, (toclevel <= depth) ? yes : no);
                        item->setText(2, (toclevel <= toc) ? yes : no);
                }
Index: src/frontends/qt4/QLToolbar.cpp
===================================================================
--- src/frontends/qt4/QLToolbar.cpp     (revision 19003)
+++ src/frontends/qt4/QLToolbar.cpp     (working copy)
@@ -81,11 +81,11 @@
 }
 
 
-void QLayoutBox::set(string const & layout)
+void QLayoutBox::set(docstring const & layout)
 {
        TextClass const & tc = getTextClass(owner_);
 
-       QString const & name = qt_(tc[layout]->name());
+       QString const & name = toqstr(translateIfPossible(tc[layout]->name()));
 
        int i = 0;
        for (; i < combo_->count(); ++i) {
@@ -116,7 +116,7 @@
        for (; it != end; ++it) {
                // ignore obsolete entries
                if ((*it)->obsoleted_by().empty())
-                       combo_->addItem(qt_((*it)->name()));
+                       
combo_->addItem(toqstr(translateIfPossible((*it)->name())));
        }
 
        // needed to recalculate size hint
@@ -152,11 +152,9 @@
 
 void QLayoutBox::selected(const QString & str)
 {
-       string const sel = fromqstr(str);
-
        owner_.setFocus();
 
-       layoutSelected(owner_, sel);
+       layoutSelected(owner_, qstring_to_ucs4(str));
 }
 
 
Index: src/frontends/qt4/QLToolbar.h
===================================================================
--- src/frontends/qt4/QLToolbar.h       (revision 19003)
+++ src/frontends/qt4/QLToolbar.h       (working copy)
@@ -40,7 +40,7 @@
        QLayoutBox(QToolBar *, GuiView &);
 
        /// select the right layout in the combox.
-       void set(std::string const & layout);
+       void set(docstring const & layout);
        /// Populate the layout combox.
        void update();
        /// Erase the layout list.
Index: src/frontends/Toolbars.cpp
===================================================================
--- src/frontends/Toolbars.cpp  (revision 19003)
+++ src/frontends/Toolbars.cpp  (working copy)
@@ -292,7 +292,7 @@
 }
 
 
-void Toolbars::setLayout(string const & layout)
+void Toolbars::setLayout(docstring const & layout)
 {
        if (layout_)
                layout_->set(layout);
@@ -370,16 +370,15 @@
 }
 
 
-void layoutSelected(LyXView & lv, string const & name)
+void layoutSelected(LyXView & lv, docstring const & name)
 {
        TextClass const & tc = lv.buffer()->params().getTextClass();
 
        TextClass::const_iterator it  = tc.begin();
        TextClass::const_iterator const end = tc.end();
        for (; it != end; ++it) {
-               string const & itname = (*it)->name();
-               // Yes, the lyx::to_utf8(_()) is correct
-               if (lyx::to_utf8(_(itname)) == name) {
+               docstring const & itname = (*it)->name();
+               if (translateIfPossible(itname) == name) {
                        FuncRequest const func(LFUN_LAYOUT, itname,
                                               FuncRequest::TOOLBAR);
                        lv.dispatch(func);
Index: src/frontends/Toolbars.h
===================================================================
--- src/frontends/Toolbars.h    (revision 19003)
+++ src/frontends/Toolbars.h    (working copy)
@@ -37,7 +37,7 @@
 public:
        virtual ~LayoutBox() {}
        /// Select the correct layout in the combox.
-       virtual void set(std::string const & layout) = 0;
+       virtual void set(docstring const & layout) = 0;
        /// Populate the layout combox.
        virtual void update() = 0;
        /// Erase the layout list.
@@ -108,7 +108,7 @@
        void saveToolbarInfo();
 
        /// Select the right layout in the combox.
-       void setLayout(std::string const & layout);
+       void setLayout(docstring const & layout);
 
        /** Populate the layout combox - returns whether we did a full
         *  update or not
@@ -155,7 +155,7 @@
 };
 
 /// Set the layout in the kernel when an entry has been selected
-void layoutSelected(LyXView & lv, std::string const & name);
+void layoutSelected(LyXView & lv, docstring const & name);
 
 
 } // namespace lyx
Index: src/insets/InsetEnvironment.cpp
===================================================================
--- src/insets/InsetEnvironment.cpp     (revision 19003)
+++ src/insets/InsetEnvironment.cpp     (working copy)
@@ -27,8 +27,8 @@
 
 
 InsetEnvironment::InsetEnvironment
-               (BufferParams const & bp, string const & name)
-       : InsetText(bp), layout_(bp.getTextClass()[name]), 
name_(from_utf8(name))
+               (BufferParams const & bp, docstring const & name)
+       : InsetText(bp), layout_(bp.getTextClass()[name]), name_(name)
 {
        setAutoBreakRows(true);
        setDrawFrame(true);
Index: src/insets/InsetEnvironment.h
===================================================================
--- src/insets/InsetEnvironment.h       (revision 19003)
+++ src/insets/InsetEnvironment.h       (working copy)
@@ -21,7 +21,7 @@
 class InsetEnvironment : public InsetText {
 public:
        ///
-       InsetEnvironment(BufferParams const &, std::string const & name);
+       InsetEnvironment(BufferParams const &, docstring const & name);
        ///
        docstring name() const { return name_; }
        ///
Index: src/LaTeXFeatures.cpp
===================================================================
--- src/LaTeXFeatures.cpp       (revision 19003)
+++ src/LaTeXFeatures.cpp       (working copy)
@@ -254,7 +254,7 @@
 }
 
 
-void LaTeXFeatures::useLayout(string const & layoutname)
+void LaTeXFeatures::useLayout(docstring const & layoutname)
 {
        // Some code to avoid loops in dependency definition
        static int level = 0;
@@ -262,15 +262,15 @@
        if (level > maxlevel) {
                lyxerr << "LaTeXFeatures::useLayout: maximum level of "
                       << "recursion attained by layout "
-                      << layoutname << endl;
+                      << to_utf8(layoutname) << endl;
                return;
        }
 
        TextClass const & tclass = params_.getTextClass();
        if (tclass.hasLayout(layoutname)) {
                // Is this layout already in usedLayouts?
-               list<string>::const_iterator cit = usedLayouts_.begin();
-               list<string>::const_iterator end = usedLayouts_.end();
+               list<docstring>::const_iterator cit = usedLayouts_.begin();
+               list<docstring>::const_iterator end = usedLayouts_.end();
                for (; cit != end; ++cit) {
                        if (layoutname == *cit)
                                return;
@@ -285,7 +285,7 @@
                usedLayouts_.push_back(layoutname);
        } else {
                lyxerr << "LaTeXFeatures::useLayout: layout `"
-                      << layoutname << "' does not exist in this class"
+                      << to_utf8(layoutname) << "' does not exist in this 
class"
                       << endl;
        }
 
@@ -712,8 +712,8 @@
 
        tcpreamble << tclass.preamble();
 
-       list<string>::const_iterator cit = usedLayouts_.begin();
-       list<string>::const_iterator end = usedLayouts_.end();
+       list<docstring>::const_iterator cit = usedLayouts_.begin();
+       list<docstring>::const_iterator end = usedLayouts_.end();
        for (; cit != end; ++cit) {
                tcpreamble << tclass[*cit]->preamble();
        }
Index: src/LaTeXFeatures.h
===================================================================
--- src/LaTeXFeatures.h (revision 19003)
+++ src/LaTeXFeatures.h (working copy)
@@ -91,7 +91,7 @@
        ///
        std::set<std::string> getEncodingSet(std::string const & doc_encoding) 
const;
        ///
-       void useLayout(std::string const & lyt);
+       void useLayout(docstring const & lyt);
        ///
        Buffer const & buffer() const;
        ///
@@ -104,7 +104,7 @@
        OutputParams const & runparams() const { return runparams_; }
 
 private:
-       std::list<std::string> usedLayouts_;
+       std::list<docstring> usedLayouts_;
 
        /// Static preamble bits from the external material insets
        typedef std::list<std::string> FeaturesList;
Index: src/Layout.cpp
===================================================================
--- src/Layout.cpp      (revision 19003)
+++ src/Layout.cpp      (working copy)
@@ -212,16 +212,16 @@
 
                case LT_COPYSTYLE:     // initialize with a known style
                        if (lexrc.next()) {
-                               string const style = subst(lexrc.getString(),
+                               docstring const style = 
subst(lexrc.getDocString(),
                                                                '_', ' ');
 
                                if (tclass.hasLayout(style)) {
-                                       string const tmpname = name_;
+                                       docstring const tmpname = name_;
                                        this->operator=(*tclass[style]);
                                        name_ = tmpname;
                                } else {
                                        lyxerr << "Cannot copy unknown style `"
-                                              << style << "'\n"
+                                              << to_utf8(style) << "'\n"
                                               << "All layouts so far:"
                                               << endl;
                                        TextClass::const_iterator it =
@@ -229,7 +229,7 @@
                                        TextClass::const_iterator end =
                                                tclass.end();
                                        for (; it != end; ++it) {
-                                               lyxerr << (*it)->name()
+                                               lyxerr << to_utf8((*it)->name())
                                                       << endl;
                                        }
 
@@ -241,16 +241,17 @@
 
                case LT_OBSOLETEDBY:     // replace with a known style
                        if (lexrc.next()) {
-                               string const style = lexrc.getString();
+                               docstring const style = lexrc.getDocString();
 
                                if (tclass.hasLayout(style)) {
-                                       string const tmpname = name_;
+                                       docstring const tmpname = name_;
                                        this->operator=(*tclass[style]);
                                        name_ = tmpname;
                                        if (obsoleted_by().empty())
                                                obsoleted_by_ = style;
                                } else {
-                                       lyxerr << "Cannot replace with unknown 
style `" << style << '\'' << endl;
+                                       lyxerr << "Cannot replace with unknown 
style `" 
+                                               << to_utf8(style) << '\'' << 
endl;
 
                                        //lexrc.printError("Cannot replace with"
                                        //               " unknown style "
@@ -261,7 +262,7 @@
 
                case LT_DEPENDSON:
                        if (lexrc.next())
-                               depends_on_ = lexrc.getString();
+                               depends_on_ = lexrc.getDocString();
                        break;
 
                case LT_MARGIN:         // margin style definition.
@@ -797,33 +798,34 @@
 }
 
 
-string const & Layout::name() const
+docstring const & Layout::name() const
 {
        return name_;
 }
 
 
-void Layout::setName(string const & n)
+void Layout::setName(docstring const & n)
 {
        name_ = n;
 }
 
 
-string const & Layout::obsoleted_by() const
+docstring const & Layout::obsoleted_by() const
 {
        return obsoleted_by_;
 }
 
 
-string const & Layout::depends_on() const
+docstring const & Layout::depends_on() const
 {
        return depends_on_;
 }
 
+
 Layout * Layout::forCaption()
 {
        Layout * lay = new Layout();
-       lay->name_ = "Caption";
+       lay->name_ = from_ascii("Caption");
        lay->latexname_ = "caption";
        lay->latextype = LATEX_COMMAND;
        lay->optionalargs = 1;
Index: src/Layout.h
===================================================================
--- src/Layout.h        (revision 19003)
+++ src/Layout.h        (working copy)
@@ -188,13 +188,13 @@
        ///
        void readSpacing(Lexer &);
        ///
-       std::string const & name() const;
+       docstring const & name() const;
        ///
-       void setName(std::string const & n);
+       void setName(docstring const & n);
        ///
-       std::string const & obsoleted_by() const;
+       docstring const & obsoleted_by() const;
        ///
-       std::string const & depends_on() const;
+       docstring const & depends_on() const;
        ///
        std::string const & latexname() const { return latexname_; }
        ///
@@ -345,19 +345,19 @@
 
 private:
        /// Name of the layout/paragraph environment
-       std::string name_;
+       docstring name_;
 
        /** Name of an layout that has replaced this layout.
            This is used to rename a layout, while keeping backward
            compatibility
        */
-       std::string obsoleted_by_;
+       docstring obsoleted_by_;
 
        /** Name of an layout which preamble must come before this one
            This is used when the preamble snippet uses macros defined in
            another preamble
         */
-       std::string depends_on_;
+       docstring depends_on_;
 
        /// LaTeX name for environment
        std::string latexname_;
Index: src/output_plaintext.cpp
===================================================================
--- src/output_plaintext.cpp    (revision 19003)
+++ src/output_plaintext.cpp    (working copy)
@@ -89,7 +89,7 @@
        depth_type depth = par.params().depth();
 
        // First write the layout
-       string const & tmp = par.layout()->name();
+       string const tmp = to_utf8(par.layout()->name());
        if (compare_ascii_no_case(tmp, "itemize") == 0) {
                ltype = 1;
                ltype_depth = depth + 1;
Index: src/Paragraph.cpp
===================================================================
--- src/Paragraph.cpp   (revision 19003)
+++ src/Paragraph.cpp   (working copy)
@@ -1110,7 +1110,7 @@
        }
 
        // First write the layout
-       os << "\n\\begin_layout " << layout()->name() << '\n';
+       os << "\n\\begin_layout " << to_utf8(layout()->name()) << '\n';
 
        params().write(os);
 
@@ -1640,8 +1640,7 @@
                size_t const j = fmt.find('@', i + 1);
                if (j != docstring::npos) {
                        docstring parent(fmt, i + 1, j - i - 1);
-                       // FIXME UNICODE
-                       docstring label = expandLabel(tclass[to_utf8(parent)], 
bparams);
+                       docstring label = expandLabel(tclass[parent], bparams);
                        fmt = docstring(fmt, 0, i) + label + docstring(fmt, j + 
1, docstring::npos);
                }
        }
Index: src/tex2lyx/Context.cpp
===================================================================
--- src/tex2lyx/Context.cpp     (revision 19003)
+++ src/tex2lyx/Context.cpp     (working copy)
@@ -28,7 +28,7 @@
 void begin_layout(ostream & os, Layout_ptr layout, TeXFont const & font,
                  TeXFont const & normalfont)
 {
-       os << "\n\\begin_layout " << layout->name() << "\n";
+       os << "\n\\begin_layout " << to_utf8(layout->name()) << "\n";
        // FIXME: This is not enough for things like
        // \\Huge par1 \\par par2
        output_font_change(os, normalfont, font);
@@ -231,8 +231,8 @@
        if (!extra_stuff.empty())
                os << "extrastuff=[" << extra_stuff << "] ";
        os << "textclass=" << textclass.name()
-          << " layout=" << layout->name()
-          << " parent_layout=" << parent_layout->name() << "] font=["
+          << " layout=" << to_utf8(layout->name())
+          << " parent_layout=" << to_utf8(parent_layout->name()) << "] font=["
           << font.size << ' ' << font.family << ' ' << font.series << ' '
           << font.shape << ']' << endl;
 }
Index: src/tex2lyx/text.cpp
===================================================================
--- src/tex2lyx/text.cpp        (revision 19003)
+++ src/tex2lyx/text.cpp        (working copy)
@@ -1051,7 +1051,7 @@
        }
 
        if (!scrap || !context.new_layout_allowed ||
-           !context.textclass.hasLayout("Scrap")) {
+           !context.textclass.hasLayout(from_ascii("Scrap"))) {
                cerr << "Warning: Could not interpret '" << name
                     << "'. Ignoring it." << endl;
                return;
@@ -1064,7 +1064,8 @@
        // noweb code chunks are implemented with a layout style in LyX they
        // always must be in an own paragraph.
        context.new_paragraph(os);
-       Context newcontext(true, context.textclass, context.textclass["Scrap"]);
+       Context newcontext(true, context.textclass,
+               context.textclass[from_ascii("Scrap")]);
        newcontext.check_layout(os);
        os << name;
        while (p.good()) {
Index: src/Text.cpp
===================================================================
--- src/Text.cpp        (revision 19003)
+++ src/Text.cpp        (working copy)
@@ -118,7 +118,7 @@
 #endif
        } else if (token == "\\begin_layout") {
                lex.eatLine();
-               string layoutname = lex.getString();
+               docstring layoutname = lex.getDocString();
 
                font = Font(Font::ALL_INHERIT, bp.language);
                change = Change(Change::UNCHANGED);
@@ -134,7 +134,7 @@
                if (!hasLayout) {
                        errorList.push_back(ErrorItem(_("Unknown layout"),
                        bformat(_("Layout '%1$s' does not exist in textclass 
'%2$s'\nTrying to use the default instead.\n"),
-                       from_utf8(layoutname), from_utf8(tclass.name())), 
par.id(), 0, par.size()));
+                       layoutname, from_utf8(tclass.name())), par.id(), 0, 
par.size()));
                        layoutname = tclass.defaultLayoutName();
                }
 
Index: src/Text.h
===================================================================
--- src/Text.h  (revision 19003)
+++ src/Text.h  (working copy)
@@ -81,10 +81,10 @@
 
        /// set layout over selection
        void setLayout(Buffer const & buffer, pit_type start, pit_type end,
-               std::string const & layout);
+               docstring const & layout);
        /// Set given layout to current cursor position.
        /// FIXME: replace Cursor with DocIterator.
-       void setLayout(Cursor & cur, std::string const & layout);
+       void setLayout(Cursor & cur, docstring const & layout);
 
        /// what type of depth change to make
        enum DEPTH_CHANGE {
Index: src/Text2.cpp
===================================================================
--- src/Text2.cpp       (revision 19003)
+++ src/Text2.cpp       (working copy)
@@ -358,7 +358,7 @@
 
 
 void Text::setLayout(Buffer const & buffer, pit_type start, pit_type end,
-               string const & layout)
+               docstring const & layout)
 {
        BOOST_ASSERT(start != end);
 
@@ -376,7 +376,7 @@
 
 
 // set layout over selection and make a total rebreak of those paragraphs
-void Text::setLayout(Cursor & cur, string const & layout)
+void Text::setLayout(Cursor & cur, docstring const & layout)
 {
        BOOST_ASSERT(this == cur.text());
        // special handling of new environment insets
@@ -385,7 +385,7 @@
        Layout_ptr const & lyxlayout = params.getTextClass()[layout];
        if (lyxlayout->is_environment) {
                // move everything in a new environment inset
-               LYXERR(Debug::DEBUG) << "setting layout " << layout << endl;
+               LYXERR(Debug::DEBUG) << "setting layout " << to_utf8(layout) << 
endl;
                lyx::dispatch(FuncRequest(LFUN_LINE_BEGIN));
                lyx::dispatch(FuncRequest(LFUN_LINE_END_SELECT));
                lyx::dispatch(FuncRequest(LFUN_CUT));
Index: src/Text3.cpp
===================================================================
--- src/Text3.cpp       (revision 19003)
+++ src/Text3.cpp       (working copy)
@@ -90,7 +90,7 @@
 using std::ostringstream;
 
 
-extern string current_layout;
+extern docstring current_layout;
 
 
 namespace {
@@ -882,12 +882,12 @@
                break;
 
        case LFUN_SERVER_GET_LAYOUT:
-               cur.message(from_utf8(cur.paragraph().layout()->name()));
+               cur.message(cur.paragraph().layout()->name());
                break;
 
        case LFUN_LAYOUT: {
-               string layout = to_ascii(cmd.argument());
-               LYXERR(Debug::INFO) << "LFUN_LAYOUT: (arg) " << layout << endl;
+               docstring layout = cmd.argument();
+               LYXERR(Debug::INFO) << "LFUN_LAYOUT: (arg) " << to_utf8(layout) 
<< endl;
 
                // Derive layout number from given argument (string)
                // and current buffer's textclass (number)
@@ -898,7 +898,7 @@
 
                // If the entry is obsolete, use the new one instead.
                if (hasLayout) {
-                       string const & obs = tclass[layout]->obsoleted_by();
+                       docstring const & obs = tclass[layout]->obsoleted_by();
                        if (!obs.empty())
                                layout = obs;
                }
Index: src/TextClass.cpp
===================================================================
--- src/TextClass.cpp   (revision 19003)
+++ src/TextClass.cpp   (working copy)
@@ -18,9 +18,12 @@
 #include "debug.h"
 #include "Lexer.h"
 #include "Counters.h"
+#include "gettext.h"
 #include "Floating.h"
 #include "FloatList.h"
 
+#include "frontends/alert.h"
+
 #include "support/lstrings.h"
 #include "support/lyxlib.h"
 #include "support/filetools.h"
@@ -53,7 +56,7 @@
 
 class LayoutNamesEqual : public std::unary_function<Layout_ptr, bool> {
 public:
-       LayoutNamesEqual(string const & name)
+       LayoutNamesEqual(docstring const & name)
                : name_(name)
        {}
        bool operator()(Layout_ptr const & c) const
@@ -61,7 +64,7 @@
                return c->name() == name_;
        }
 private:
-       string name_;
+       docstring name_;
 };
 
 
@@ -127,7 +130,7 @@
 
 bool TextClass::do_readStyle(Lexer & lexrc, Layout & lay)
 {
-       LYXERR(Debug::TCLASS) << "Reading style " << lay.name() << endl;
+       LYXERR(Debug::TCLASS) << "Reading style " << to_utf8(lay.name()) << 
endl;
        if (!lay.read(lexrc, *this)) {
                // Resolve fonts
                lay.resfont = lay.font;
@@ -136,7 +139,7 @@
                lay.reslabelfont.realize(defaultfont());
                return false; // no errors
        }
-       lyxerr << "Error parsing style `" << lay.name() << '\'' << endl;
+       lyxerr << "Error parsing style `" << to_utf8(lay.name()) << '\'' << 
endl;
        return true;
 }
 
@@ -271,8 +274,8 @@
 
                case TC_DEFAULTSTYLE:
                        if (lexrc.next()) {
-                               string const name = subst(lexrc.getString(),
-                                                         '_', ' ');
+                               docstring const name = 
from_utf8(subst(lexrc.getString(),
+                                                         '_', ' '));
                                defaultlayout_ = name;
                        }
                        break;
@@ -280,9 +283,15 @@
                case TC_ENVIRONMENT:
                case TC_STYLE:
                        if (lexrc.next()) {
-                               string const name = subst(lexrc.getString(),
-                                                   '_', ' ');
-                               if (hasLayout(name)) {
+                               docstring const name = 
from_utf8(subst(lexrc.getString(),
+                                                   '_', ' '));
+                               if (name.empty()) {
+                                       string s = "Could not read name for 
style: `$$Token' "
+                                               + lexrc.getString() + " is 
probably not valid UTF-8!";
+                                       lexrc.printError(s.c_str());
+                                       Layout lay;
+                                       error = do_readStyle(lexrc, lay);
+                               } else if (hasLayout(name)) {
                                        Layout * lay = operator[](name).get();
                                        error = do_readStyle(lexrc, *lay);
                                } else {
@@ -313,11 +322,11 @@
 
                case TC_NOSTYLE:
                        if (lexrc.next()) {
-                               string const style = subst(lexrc.getString(),
-                                                    '_', ' ');
+                               docstring const style = 
from_utf8(subst(lexrc.getString(),
+                                                    '_', ' '));
                                if (!delete_layout(style))
                                        lyxerr << "Cannot delete style `"
-                                              << style << '\'' << endl;
+                                              << to_utf8(style) << '\'' << 
endl;
 //                                     lexrc.printError("Cannot delete style"
 //                                                      " `$$Token'");
                        }
@@ -850,9 +859,9 @@
 }
 
 
-bool TextClass::hasLayout(string const & n) const
+bool TextClass::hasLayout(docstring const & n) const
 {
-       string const name = (n.empty() ? defaultLayoutName() : n);
+       docstring const name = n.empty() ? defaultLayoutName() : n;
 
        return find_if(layoutlist_.begin(), layoutlist_.end(),
                       LayoutNamesEqual(name))
@@ -861,7 +870,7 @@
 
 
 
-Layout_ptr const & TextClass::operator[](string const & name) const
+Layout_ptr const & TextClass::operator[](docstring const & name) const
 {
        BOOST_ASSERT(!name.empty());
 
@@ -871,12 +880,12 @@
                        LayoutNamesEqual(name));
 
        if (cit == layoutlist_.end()) {
-               lyxerr << "We failed to find the layout '" << name
+               lyxerr << "We failed to find the layout '" << to_utf8(name)
                       << "' in the layout list. You MUST investigate!"
                       << endl;
                for (LayoutList::const_iterator it = layoutlist_.begin();
                         it != layoutlist_.end(); ++it)
-                       lyxerr  << " " << it->get()->name() << endl;
+                       lyxerr  << " " << to_utf8(it->get()->name()) << endl;
 
                // we require the name to exist
                BOOST_ASSERT(false);
@@ -887,7 +896,7 @@
 
 
 
-bool TextClass::delete_layout(string const & name)
+bool TextClass::delete_layout(docstring const & name)
 {
        if (name == defaultLayoutName())
                return false;
@@ -959,7 +968,7 @@
 }
 
 
-string const & TextClass::defaultLayoutName() const
+docstring const & TextClass::defaultLayoutName() const
 {
        // This really should come from the actual layout... (Lgb)
        return defaultlayout_;
Index: src/TextClass.h
===================================================================
--- src/TextClass.h     (revision 19003)
+++ src/TextClass.h     (working copy)
@@ -83,10 +83,10 @@
        ///
        void readCounter(Lexer &);
        ///
-       bool hasLayout(std::string const & name) const;
+       bool hasLayout(docstring const & name) const;
 
        ///
-       Layout_ptr const & operator[](std::string const & vname) const;
+       Layout_ptr const & operator[](docstring const & vname) const;
 
        /// Sees to that the textclass structure has been loaded
        bool load(std::string const & path = std::string()) const;
@@ -104,7 +104,7 @@
        /// Retrieve element of name s:
        CharStyles::iterator charstyle(std::string const & s) const;
        ///
-       std::string const & defaultLayoutName() const;
+       docstring const & defaultLayoutName() const;
        ///
        Layout_ptr const & defaultLayout() const;
        ///
@@ -172,7 +172,7 @@
        bool hasTocLevels() const;
 private:
        ///
-       bool delete_layout(std::string const &);
+       bool delete_layout(docstring const &);
        ///
        bool do_readStyle(Lexer &, Layout &);
        /// Layout file name
@@ -192,7 +192,7 @@
        ///
        std::string class_header_;
        ///
-       std::string defaultlayout_;
+       docstring defaultlayout_;
        /// preamble text to support layout styles
        docstring preamble_;
        /// latex packages loaded by document class.

Reply via email to