Am Freitag, 10. November 2006 11:22 schrieb Georg Baum:
> Jean-Marc Lasgouttes wrote:
>
> >>>>>> "Georg" == Georg Baum
> >>>>>> <[EMAIL PROTECTED]>
> >>>>>> writes:
> >
> > Georg> BTW, why is layout->labelstring() sometimes used untranslated?
> >
> > Where?
>
> When setting the setLabelWidthString of ParagraphParameters. This updated
> patch does also translate these cases. Is this OK, or is there some
special
> reason for not translating these cases?
Oops, forgot the patch. This one is now going in, if the addtitional
translations are wrong please shout.
Georg
Index: src/text2.C
===================================================================
--- src/text2.C (Revision 15853)
+++ src/text2.C (Arbeitskopie)
@@ -352,7 +352,7 @@ void LyXText::setLayout(Buffer const & b
for (pit_type pit = start; pit != end; ++pit) {
pars_[pit].applyLayout(lyxlayout);
if (lyxlayout->margintype == MARGIN_MANUAL)
- pars_[pit].setLabelWidthString(lyxlayout->labelstring());
+ pars_[pit].setLabelWidthString(buffer.translateLabel(lyxlayout->labelstring()));
}
}
@@ -604,7 +604,7 @@ docstring LyXText::getStringToIndex(LCur
void LyXText::setParagraph(LCursor & cur,
Spacing const & spacing, LyXAlignment align,
- string const & labelwidthstring, bool noindent)
+ docstring const & labelwidthstring, bool noindent)
{
BOOST_ASSERT(cur.text());
// make sure that the depth behind the selection are restored, too
@@ -628,8 +628,7 @@ void LyXText::setParagraph(LCursor & cur
else
params.align(align);
}
- // FIXME UNICODE
- par.setLabelWidthString(from_ascii(labelwidthstring));
+ par.setLabelWidthString(labelwidthstring);
params.noindent(noindent);
}
}
Index: src/buffer.C
===================================================================
--- src/buffer.C (Revision 15853)
+++ src/buffer.C (Arbeitskopie)
@@ -1445,6 +1445,18 @@ docstring const Buffer::B_(string 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 can not translate
+ // this, since gettext accepts only ascii keys.
+ return label;
+}
+
+
bool Buffer::isClean() const
{
return pimpl_->lyx_clean;
Index: src/lyxtext.h
===================================================================
--- src/lyxtext.h (Revision 15854)
+++ src/lyxtext.h (Arbeitskopie)
@@ -260,7 +260,7 @@ public:
void setParagraph(LCursor & cur,
Spacing const & spacing,
LyXAlignment align,
- std::string const & labelwidthstring,
+ docstring const & labelwidthstring,
bool noindent);
/* these things are for search and replace */
Index: src/buffer.h
===================================================================
--- src/buffer.h (Revision 15853)
+++ src/buffer.h (Arbeitskopie)
@@ -170,6 +170,8 @@ 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: src/support/lstrings.C
===================================================================
--- src/support/lstrings.C (Revision 15853)
+++ src/support/lstrings.C (Arbeitskopie)
@@ -279,6 +279,16 @@ int hexToInt(docstring const & str)
}
+bool isAscii(docstring const & str)
+{
+ int const len = str.length();
+ for (int i = 0; i < len; ++i)
+ if (str[i] >= 0x80)
+ return false;
+ return true;
+}
+
+
char lowercase(char c)
{
return char(tolower(c));
Index: src/support/lstrings.h
===================================================================
--- src/support/lstrings.h (Revision 15853)
+++ src/support/lstrings.h (Arbeitskopie)
@@ -72,6 +72,9 @@ bool isHex(lyx::docstring const & str);
int hexToInt(lyx::docstring const & str);
+/// is \p str pure ascii?
+bool isAscii(docstring const & str);
+
///
char lowercase(char c);
Index: src/text3.C
===================================================================
--- src/text3.C (Revision 15854)
+++ src/text3.C (Arbeitskopie)
@@ -1411,7 +1411,7 @@ void LyXText::dispatch(LCursor & cur, Fu
}
setLayout(cur, tclass.defaultLayoutName());
- setParagraph(cur, Spacing(), LYX_ALIGN_LAYOUT, string(), 0);
+ setParagraph(cur, Spacing(), LYX_ALIGN_LAYOUT, docstring(), 0);
insertInset(cur, new InsetFloatList(to_utf8(cmd.argument())));
cur.posRight();
} else {
@@ -1455,11 +1455,10 @@ void LyXText::dispatch(LCursor & cur, Fu
lex.setStream(is);
ParagraphParameters params;
params.read(lex);
- // FIXME UNICODE
setParagraph(cur,
params.spacing(),
params.align(),
- to_ascii(params.labelWidthString()),
+ params.labelWidthString(),
params.noindent());
cur.message(_("Paragraph layout set"));
break;
Index: src/lyxlayout.C
===================================================================
--- src/lyxlayout.C (Revision 15853)
+++ src/lyxlayout.C (Arbeitskopie)
@@ -451,17 +451,17 @@ bool LyXLayout::read(LyXLex & lexrc, LyX
case LT_LABELSTRING: // label string definition
if (lexrc.next())
- labelstring_ = lyx::from_ascii(trim(lexrc.getString()));
+ labelstring_ = trim(lexrc.getDocString());
break;
case LT_ENDLABELSTRING: // endlabel string definition
if (lexrc.next())
- endlabelstring_ = lyx::from_ascii(trim(lexrc.getString()));
+ endlabelstring_ = trim(lexrc.getDocString());
break;
case LT_LABELSTRING_APPENDIX: // label string appendix definition
if (lexrc.next())
- labelstring_appendix_ = lyx::from_ascii(trim(lexrc.getString()));
+ labelstring_appendix_ = trim(lexrc.getDocString());
break;
case LT_LABELCOUNTER: // name of counter to use
Index: src/buffer_funcs.C
===================================================================
--- src/buffer_funcs.C (Revision 15853)
+++ src/buffer_funcs.C (Arbeitskopie)
@@ -43,8 +43,6 @@
#include "support/fs_extras.h"
#include "support/lyxlib.h"
-#include <iostream>
-
#include <boost/bind.hpp>
#include <boost/filesystem/operations.hpp>
@@ -376,7 +374,7 @@ void setLabel(Buffer const & buf, ParIte
if (layout->margintype == MARGIN_MANUAL) {
if (par.params().labelWidthString().empty())
- par.setLabelWidthString(layout->labelstring());
+ par.setLabelWidthString(buf.translateLabel(layout->labelstring()));
} else {
par.setLabelWidthString(docstring());
}
@@ -468,8 +466,7 @@ void setLabel(Buffer const & buf, ParIte
int number = counters.value(from_ascii("bibitem"));
if (par.bibitem())
par.bibitem()->setCounter(number);
- // FIXME UNICODE
- par.params().labelString(buf.B_(to_ascii(layout->labelstring())));
+ par.params().labelString(buf.translateLabel(layout->labelstring()));
// In biblio should't be following counters but...
} else if (layout->labeltype == LABEL_SENSITIVE) {
// Search for the first float or wrap inset in the iterator
@@ -495,16 +492,14 @@ void setLabel(Buffer const & buf, ParIte
s = bformat(_("%1$s #:"), buf.B_(fl.name()));
} else {
// par->SetLayout(0);
- // FIXME UNICODE
- s = buf.B_(to_ascii(layout->labelstring()));
+ s = buf.translateLabel(layout->labelstring());
}
par.params().labelString(s);
} else if (layout->labeltype == LABEL_NO_LABEL)
par.params().labelString(docstring());
else
- // FIXME UNICODE
- par.params().labelString(buf.B_(to_ascii(layout->labelstring())));
+ par.params().labelString(buf.translateLabel(layout->labelstring()));
}
} // anon namespace
@@ -596,9 +591,9 @@ docstring expandLabel(Buffer const & buf
{
LyXTextClass const & tclass = buf.params().getLyXTextClass();
- // FIXME UNICODE
- docstring fmt = buf.B_(to_ascii(appendix ? layout->labelstring_appendix()
- : layout->labelstring()));
+ docstring fmt = buf.translateLabel(appendix ?
+ layout->labelstring_appendix() :
+ layout->labelstring());
// handle 'inherited level parts' in 'fmt',
// i.e. the stuff between '@' in '@[EMAIL PROTECTED]'