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
This commit is contained in:
Abdelrazak Younes 2007-01-15 16:58:14 +00:00
parent 6cbc6d9624
commit e68d69e473
8 changed files with 76 additions and 64 deletions

View 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 bool Buffer::isClean() const
{ {
return pimpl_->lyx_clean; return pimpl_->lyx_clean;

View File

@ -200,8 +200,6 @@ public:
Language const * getLanguage() const; Language const * getLanguage() const;
/// get l10n translated to the buffers language /// get l10n translated to the buffers language
docstring const B_(std::string const & l10n) const; 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(); int runChktex();

View File

@ -374,9 +374,9 @@ void setLabel(Buffer const & buf, ParIterator & it, LyXTextClass const & textcla
if (layout->margintype == MARGIN_MANUAL) { if (layout->margintype == MARGIN_MANUAL) {
if (par.params().labelWidthString().empty()) if (par.params().labelWidthString().empty())
par.setLabelWidthString(buf.translateLabel(layout->labelstring())); par.params().labelWidthString(par.translateIfPossible(layout->labelstring(), buf.params()));
} else { } else {
par.setLabelWidthString(docstring()); par.params().labelWidthString(docstring());
} }
// Optimisation: setLabel() can be called for each for each // 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 && (layout->latextype != LATEX_ENVIRONMENT
|| isFirstInSequence(it.pit(), it.plist()))) { || isFirstInSequence(it.pit(), it.plist()))) {
counters.step(layout->counter); counters.step(layout->counter);
itemlabel = expandLabel(buf, layout, par.params().labelString(
par.params().appendix()); par.expandLabel(layout, buf.params()));
} else } else
itemlabel.clear(); par.params().labelString(docstring());
} else if (layout->labeltype == LABEL_ITEMIZE) { } else if (layout->labeltype == LABEL_ITEMIZE) {
// At some point of time we should do something more // 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 itemlabel = char_type(0x2219); // or 0x00b7
break; break;
} }
par.params().labelString(itemlabel);
} else if (layout->labeltype == LABEL_ENUMERATE) { } else if (layout->labeltype == LABEL_ENUMERATE) {
// FIXME // FIXME
@ -464,7 +465,8 @@ void setLabel(Buffer const & buf, ParIterator & it, LyXTextClass const & textcla
break; 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 } else if (layout->labeltype == LABEL_BIBLIO) {// ale970302
counters.step(from_ascii("bibitem")); counters.step(from_ascii("bibitem"));
@ -472,8 +474,9 @@ void setLabel(Buffer const & buf, ParIterator & it, LyXTextClass const & textcla
if (par.bibitem()) if (par.bibitem())
par.bibitem()->setCounter(number); par.bibitem()->setCounter(number);
itemlabel = buf.translateLabel(layout->labelstring()); par.params().labelString(
// In biblio should't be following counters but... par.translateIfPossible(layout->labelstring(), buf.params()));
// In biblio shouldn'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
size_t i = it.depth(); 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())); counters.step(from_ascii(fl.type()));
// Doesn't work... yet. // 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 { } else {
// par->SetLayout(0); // par->SetLayout(0);
itemlabel = buf.translateLabel(layout->labelstring()); par.params().labelString(par.translateIfPossible(
layout->labelstring(), buf.params()));
} }
} else if (layout->labeltype == LABEL_NO_LABEL) } else if (layout->labeltype == LABEL_NO_LABEL)
itemlabel.clear(); par.params().labelString(docstring());
else else
itemlabel = buf.translateLabel(layout->labelstring()); par.params().labelString(
par.translateIfPossible(layout->labelstring(), buf.params()));
par.params().labelString(itemlabel);
} }
} // anon namespace } // 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 } // namespace lyx

View File

@ -49,12 +49,6 @@ void bufferErrors(Buffer const &, TeXErrors const &, ErrorList &);
/// Count the number of words in the text between these two iterators /// Count the number of words in the text between these two iterators
int countWords(DocIterator const & from, DocIterator const & to); 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". /// update labels at "iter".
/** /**
A full updateLabels(Buffer const &) will be called if not possible. A full updateLabels(Buffer const &) will be called if not possible.

View File

@ -240,7 +240,8 @@ ParagraphList::const_iterator makeCommand(Buffer const & buf,
// Label around sectioning number: // Label around sectioning number:
if (!bstyle->labeltag().empty()) { if (!bstyle->labeltag().empty()) {
sgml::openTag(os, bstyle->labeltag()); 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()); sgml::closeTag(os, bstyle->labeltag());
} }

View File

@ -31,6 +31,7 @@
#include "lyxfont.h" #include "lyxfont.h"
#include "lyxrc.h" #include "lyxrc.h"
#include "lyxrow.h" #include "lyxrow.h"
#include "messages.h"
#include "outputparams.h" #include "outputparams.h"
#include "paragraph_funcs.h" #include "paragraph_funcs.h"
#include "ParagraphList_fwd.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) void Paragraph::applyLayout(LyXLayout_ptr const & new_layout)
{ {
layout(new_layout); layout(new_layout);

View File

@ -240,8 +240,14 @@ public:
/// the next two functions are for the manual labels /// the next two functions are for the manual labels
docstring const getLabelWidthString() const; docstring const getLabelWidthString() const;
/// /// Set label width string.
void setLabelWidthString(docstring const & s); 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 /// Actual paragraph alignment used
char getAlign() const; char getAlign() const;
/// The nesting depth of a paragraph /// The nesting depth of a paragraph

View File

@ -335,9 +335,11 @@ void LyXText::setLayout(Buffer const & buffer, pit_type start, pit_type end,
LyXLayout_ptr const & lyxlayout = bufparams.getLyXTextClass()[layout]; LyXLayout_ptr const & lyxlayout = bufparams.getLyXTextClass()[layout];
for (pit_type pit = start; pit != end; ++pit) { for (pit_type pit = start; pit != end; ++pit) {
pars_[pit].applyLayout(lyxlayout); Paragraph & par = pars_[pit];
par.applyLayout(lyxlayout);
if (lyxlayout->margintype == MARGIN_MANUAL) if (lyxlayout->margintype == MARGIN_MANUAL)
pars_[pit].setLabelWidthString(buffer.translateLabel(lyxlayout->labelstring())); par.setLabelWidthString(par.translateIfPossible(
lyxlayout->labelstring(), buffer.params()));
} }
} }