From e68d69e4739b5b9811120889fbc5147aad25e41f Mon Sep 17 00:00:00 2001 From: Abdelrazak Younes Date: Mon, 15 Jan 2007 16:58:14 +0000 Subject: [PATCH] Translate labels based on the paragraph language instead of the Buffer language. * Buffer: - translateLabel(): deleted. * Paragraph: - translateIfPossible(): new method. - expandLabel(): new method. * buffer_funcs.[Ch] - expandLabel(): deleted. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@16694 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/buffer.C | 12 --------- src/buffer.h | 2 -- src/buffer_funcs.C | 59 ++++++++++++++------------------------------ src/buffer_funcs.h | 6 ----- src/output_docbook.C | 3 ++- src/paragraph.C | 44 +++++++++++++++++++++++++++++++++ src/paragraph.h | 8 +++++- src/text2.C | 6 +++-- 8 files changed, 76 insertions(+), 64 deletions(-) diff --git a/src/buffer.C b/src/buffer.C index 155b8b6047..3752becf3f 100644 --- a/src/buffer.C +++ b/src/buffer.C @@ -1472,18 +1472,6 @@ docstring const Buffer::B_(string const & l10n) const } -docstring const Buffer::translateLabel(docstring const & label) const -{ - if (support::isAscii(label)) - // Probably standard layout, try to translate - return B_(to_ascii(label)); - else - // This must be a user defined layout. We cannot translate - // this, since gettext accepts only ascii keys. - return label; -} - - bool Buffer::isClean() const { return pimpl_->lyx_clean; diff --git a/src/buffer.h b/src/buffer.h index ac13950039..499293976f 100644 --- a/src/buffer.h +++ b/src/buffer.h @@ -200,8 +200,6 @@ public: Language const * getLanguage() const; /// get l10n translated to the buffers language docstring const B_(std::string const & l10n) const; - /// translate \p label to the buffer language if possible - docstring const translateLabel(docstring const & label) const; /// int runChktex(); diff --git a/src/buffer_funcs.C b/src/buffer_funcs.C index 66c6223806..52f9b6f5e3 100644 --- a/src/buffer_funcs.C +++ b/src/buffer_funcs.C @@ -374,9 +374,9 @@ void setLabel(Buffer const & buf, ParIterator & it, LyXTextClass const & textcla if (layout->margintype == MARGIN_MANUAL) { if (par.params().labelWidthString().empty()) - par.setLabelWidthString(buf.translateLabel(layout->labelstring())); + par.params().labelWidthString(par.translateIfPossible(layout->labelstring(), buf.params())); } else { - par.setLabelWidthString(docstring()); + par.params().labelWidthString(docstring()); } // Optimisation: setLabel() can be called for each for each @@ -390,10 +390,10 @@ void setLabel(Buffer const & buf, ParIterator & it, LyXTextClass const & textcla && (layout->latextype != LATEX_ENVIRONMENT || isFirstInSequence(it.pit(), it.plist()))) { counters.step(layout->counter); - itemlabel = expandLabel(buf, layout, - par.params().appendix()); + par.params().labelString( + par.expandLabel(layout, buf.params())); } else - itemlabel.clear(); + par.params().labelString(docstring()); } else if (layout->labeltype == LABEL_ITEMIZE) { // At some point of time we should do something more @@ -415,6 +415,7 @@ void setLabel(Buffer const & buf, ParIterator & it, LyXTextClass const & textcla itemlabel = char_type(0x2219); // or 0x00b7 break; } + par.params().labelString(itemlabel); } else if (layout->labeltype == LABEL_ENUMERATE) { // FIXME @@ -464,7 +465,8 @@ void setLabel(Buffer const & buf, ParIterator & it, LyXTextClass const & textcla break; } - itemlabel = counters.counterLabel(buf.B_(format)); + par.params().labelString(counters.counterLabel( + par.translateIfPossible(from_ascii(format), buf.params()))); } else if (layout->labeltype == LABEL_BIBLIO) {// ale970302 counters.step(from_ascii("bibitem")); @@ -472,8 +474,9 @@ void setLabel(Buffer const & buf, ParIterator & it, LyXTextClass const & textcla if (par.bibitem()) par.bibitem()->setCounter(number); - itemlabel = buf.translateLabel(layout->labelstring()); - // In biblio should't be following counters but... + par.params().labelString( + par.translateIfPossible(layout->labelstring(), buf.params())); + // In biblio shouldn't be following counters but... } else if (layout->labeltype == LABEL_SENSITIVE) { // Search for the first float or wrap inset in the iterator size_t i = it.depth(); @@ -493,18 +496,20 @@ void setLabel(Buffer const & buf, ParIterator & it, LyXTextClass const & textcla counters.step(from_ascii(fl.type())); // Doesn't work... yet. - itemlabel = bformat(_("%1$s #:"), buf.B_(fl.name())); + par.params().labelString(par.translateIfPossible( + bformat(from_ascii("%1$s #:"), from_utf8(fl.name())), + buf.params())); } else { // par->SetLayout(0); - itemlabel = buf.translateLabel(layout->labelstring()); + par.params().labelString(par.translateIfPossible( + layout->labelstring(), buf.params())); } } else if (layout->labeltype == LABEL_NO_LABEL) - itemlabel.clear(); + par.params().labelString(docstring()); else - itemlabel = buf.translateLabel(layout->labelstring()); - - par.params().labelString(itemlabel); + par.params().labelString( + par.translateIfPossible(layout->labelstring(), buf.params())); } } // anon namespace @@ -611,30 +616,4 @@ void updateLabels(Buffer const & buf, bool childonly) } -docstring expandLabel(Buffer const & buf, - LyXLayout_ptr const & layout, bool appendix) -{ - LyXTextClass const & tclass = buf.params().getLyXTextClass(); - - docstring fmt = buf.translateLabel(appendix ? - layout->labelstring_appendix() : - layout->labelstring()); - - // handle 'inherited level parts' in 'fmt', - // i.e. the stuff between '@' in '@Section@.\arabic{subsection}' - size_t const i = fmt.find('@', 0); - if (i != docstring::npos) { - 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(buf, tclass[to_utf8(parent)], appendix); - fmt = docstring(fmt, 0, i) + label + docstring(fmt, j + 1, docstring::npos); - } - } - - return tclass.counters().counterLabel(fmt); -} - - } // namespace lyx diff --git a/src/buffer_funcs.h b/src/buffer_funcs.h index 8e55562044..1e1e25ce67 100644 --- a/src/buffer_funcs.h +++ b/src/buffer_funcs.h @@ -49,12 +49,6 @@ void bufferErrors(Buffer const &, TeXErrors const &, ErrorList &); /// Count the number of words in the text between these two iterators int countWords(DocIterator const & from, DocIterator const & to); -/// Expand the counters for the labelstring of \c layout -lyx::docstring expandLabel(Buffer const & buf, - LyXLayout_ptr const & layout, - bool appendix); - - /// update labels at "iter". /** A full updateLabels(Buffer const &) will be called if not possible. diff --git a/src/output_docbook.C b/src/output_docbook.C index 970eada5ae..cb5ec45481 100644 --- a/src/output_docbook.C +++ b/src/output_docbook.C @@ -240,7 +240,8 @@ ParagraphList::const_iterator makeCommand(Buffer const & buf, // Label around sectioning number: if (!bstyle->labeltag().empty()) { sgml::openTag(os, bstyle->labeltag()); - os << expandLabel(buf, bstyle, false); + // We don't care about appendix in DOCBOOK. + os << par->expandLabel(bstyle, buf.params(), false); sgml::closeTag(os, bstyle->labeltag()); } diff --git a/src/paragraph.C b/src/paragraph.C index 858f516dc1..55af8cfc1f 100644 --- a/src/paragraph.C +++ b/src/paragraph.C @@ -31,6 +31,7 @@ #include "lyxfont.h" #include "lyxrc.h" #include "lyxrow.h" +#include "messages.h" #include "outputparams.h" #include "paragraph_funcs.h" #include "ParagraphList_fwd.h" @@ -631,6 +632,49 @@ void Paragraph::setLabelWidthString(docstring const & s) } +docstring const Paragraph::translateIfPossible(docstring const & s, + BufferParams const & bparams) const +{ + if (!support::isAscii(s) || s.empty()) { + // This must be a user defined layout. We cannot translate + // this, since gettext accepts only ascii keys. + return s; + } + // Probably standard layout, try to translate + Messages & m = getMessages(getParLanguage(bparams)->code()); + return m.get(to_ascii(s)); +} + + +docstring Paragraph::expandLabel(LyXLayout_ptr const & layout, + BufferParams const & bparams, bool process_appendix) const +{ + LyXTextClass const & tclass = bparams.getLyXTextClass(); + + docstring fmt; + if (process_appendix && params().appendix()) + fmt = translateIfPossible(layout->labelstring_appendix(), + bparams); + else + fmt = translateIfPossible(layout->labelstring(), bparams); + + // handle 'inherited level parts' in 'fmt', + // i.e. the stuff between '@' in '@Section@.\arabic{subsection}' + size_t const i = fmt.find('@', 0); + if (i != docstring::npos) { + 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); + fmt = docstring(fmt, 0, i) + label + docstring(fmt, j + 1, docstring::npos); + } + } + + return tclass.counters().counterLabel(fmt); +} + + void Paragraph::applyLayout(LyXLayout_ptr const & new_layout) { layout(new_layout); diff --git a/src/paragraph.h b/src/paragraph.h index 5fb7af6216..a2f43d5e56 100644 --- a/src/paragraph.h +++ b/src/paragraph.h @@ -240,8 +240,14 @@ public: /// the next two functions are for the manual labels docstring const getLabelWidthString() const; - /// + /// Set label width string. void setLabelWidthString(docstring const & s); + /// translate \p label to the paragraph language if possible. + docstring const translateIfPossible(docstring const & label, + BufferParams const & bparams) const; + /// Expand the counters for the labelstring of \c layout + docstring expandLabel(LyXLayout_ptr const &, BufferParams const &, + bool process_appendix = true) const; /// Actual paragraph alignment used char getAlign() const; /// The nesting depth of a paragraph diff --git a/src/text2.C b/src/text2.C index 57f52363f7..17f419b6b9 100644 --- a/src/text2.C +++ b/src/text2.C @@ -335,9 +335,11 @@ void LyXText::setLayout(Buffer const & buffer, pit_type start, pit_type end, LyXLayout_ptr const & lyxlayout = bufparams.getLyXTextClass()[layout]; for (pit_type pit = start; pit != end; ++pit) { - pars_[pit].applyLayout(lyxlayout); + Paragraph & par = pars_[pit]; + par.applyLayout(lyxlayout); if (lyxlayout->margintype == MARGIN_MANUAL) - pars_[pit].setLabelWidthString(buffer.translateLabel(lyxlayout->labelstring())); + par.setLabelWidthString(par.translateIfPossible( + lyxlayout->labelstring(), buffer.params())); } } -- 2.39.2