]> git.lyx.org Git - features.git/commitdiff
Translate labels based on the paragraph language instead of the Buffer language.
authorAbdelrazak Younes <younes@lyx.org>
Mon, 15 Jan 2007 16:58:14 +0000 (16:58 +0000)
committerAbdelrazak Younes <younes@lyx.org>
Mon, 15 Jan 2007 16:58:14 +0000 (16:58 +0000)
* 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
src/buffer.h
src/buffer_funcs.C
src/buffer_funcs.h
src/output_docbook.C
src/paragraph.C
src/paragraph.h
src/text2.C

index 155b8b6047309c4e9cc2afa890a1dad524614e8d..3752becf3f477bdb0958fff23f37a74b0062c855 100644 (file)
@@ -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;
index ac1395003909f49c7b4390e114c8afc23f4d09e1..499293976fe7dc61980cab859f1e46478a35a4c5 100644 (file)
@@ -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();
index 66c6223806bdbed7c56928694920a7c8123f6f6e..52f9b6f5e325c6f70aca3f1daabeb7a74b1c3b8c 100644 (file)
@@ -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
index 8e555620445886f30f3374bebe215fa1caba738a..1e1e25ce672226fe5b949b68e7cbf69c1ecff950 100644 (file)
@@ -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.
index 970eada5ae83828fede7416a0065044b0f8415e5..cb5ec45481dac8ea211d819230870cf5c09d8fa8 100644 (file)
@@ -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());
        }
 
index 858f516dc10697937f9cdcdd5125365d143cb250..55af8cfc1f552a2f689dc489e6958952065d6c92 100644 (file)
@@ -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);
index 5fb7af6216de2d58ce6a76093ba42367bd905a92..a2f43d5e560e6cdbb1749c9525e00958d6809a4f 100644 (file)
@@ -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
index 57f52363f7c20e5743784f83542a3250d9ab78f6..17f419b6b953ccbb370e21d85076a5b53d1a2bd9 100644 (file)
@@ -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()));
        }
 }