Make it possible to uses non-ascii labelstring, endlabelstring and

labelstring_appendix in layout files

	* src/text2.C
	(LyXText::setLayout): Translate labelwidthstring for paragraph
	(LyXText::getStringToIndex): labelwidthstring is now a docstring

	* src/buffer.[Ch]
	(Buffer::translateLabel): New method for translating a label if it
	is not already translated by the user in the layout file

	* src/lyxtext.h
	(setParagraph): labelwidthstring is now a docstring

	* src/support/lstrings.[Ch]
	(bool isAscii): New utility function: Determine whether a docstring
	contains only pure ascii

	* src/text3.C
	(LyXText::dispatch): setParagraph() now takes a docstring

	* src/lyxlayout.C
	(LyXLayout::read): Don't use from_ascii when reading labelstring_,
	endlabelstring_ and labelstring_appendix_

	* src/buffer_funcs.C
	(setLabel): labelwidthstring is now a docstring
	(setLabel): Use Buffer::translateLabel instead of Buffer::B_ to
	translate labels
	(expandLabel): ditto


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@15855 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Georg Baum 2006-11-11 12:00:34 +00:00
parent 1354f4b6d6
commit 7e7d28a0ca
9 changed files with 43 additions and 23 deletions

View File

@ -1445,6 +1445,18 @@ 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 can not 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

@ -170,6 +170,8 @@ 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

@ -43,8 +43,6 @@
#include "support/fs_extras.h" #include "support/fs_extras.h"
#include "support/lyxlib.h" #include "support/lyxlib.h"
#include <iostream>
#include <boost/bind.hpp> #include <boost/bind.hpp>
#include <boost/filesystem/operations.hpp> #include <boost/filesystem/operations.hpp>
@ -376,7 +374,7 @@ void setLabel(Buffer const & buf, ParIterator & it)
if (layout->margintype == MARGIN_MANUAL) { if (layout->margintype == MARGIN_MANUAL) {
if (par.params().labelWidthString().empty()) if (par.params().labelWidthString().empty())
par.setLabelWidthString(layout->labelstring()); par.setLabelWidthString(buf.translateLabel(layout->labelstring()));
} else { } else {
par.setLabelWidthString(docstring()); par.setLabelWidthString(docstring());
} }
@ -468,8 +466,7 @@ void setLabel(Buffer const & buf, ParIterator & it)
int number = counters.value(from_ascii("bibitem")); int number = counters.value(from_ascii("bibitem"));
if (par.bibitem()) if (par.bibitem())
par.bibitem()->setCounter(number); par.bibitem()->setCounter(number);
// FIXME UNICODE par.params().labelString(buf.translateLabel(layout->labelstring()));
par.params().labelString(buf.B_(to_ascii(layout->labelstring())));
// In biblio should't be following counters but... // In biblio should'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
@ -495,16 +492,14 @@ void setLabel(Buffer const & buf, ParIterator & it)
s = bformat(_("%1$s #:"), buf.B_(fl.name())); s = bformat(_("%1$s #:"), buf.B_(fl.name()));
} else { } else {
// par->SetLayout(0); // par->SetLayout(0);
// FIXME UNICODE s = buf.translateLabel(layout->labelstring());
s = buf.B_(to_ascii(layout->labelstring()));
} }
par.params().labelString(s); par.params().labelString(s);
} else if (layout->labeltype == LABEL_NO_LABEL) } else if (layout->labeltype == LABEL_NO_LABEL)
par.params().labelString(docstring()); par.params().labelString(docstring());
else else
// FIXME UNICODE par.params().labelString(buf.translateLabel(layout->labelstring()));
par.params().labelString(buf.B_(to_ascii(layout->labelstring())));
} }
} // anon namespace } // anon namespace
@ -596,9 +591,9 @@ docstring expandLabel(Buffer const & buf,
{ {
LyXTextClass const & tclass = buf.params().getLyXTextClass(); LyXTextClass const & tclass = buf.params().getLyXTextClass();
// FIXME UNICODE docstring fmt = buf.translateLabel(appendix ?
docstring fmt = buf.B_(to_ascii(appendix ? layout->labelstring_appendix() layout->labelstring_appendix() :
: layout->labelstring())); layout->labelstring());
// handle 'inherited level parts' in 'fmt', // handle 'inherited level parts' in 'fmt',
// i.e. the stuff between '@' in '@Section@.\arabic{subsection}' // i.e. the stuff between '@' in '@Section@.\arabic{subsection}'

View File

@ -451,17 +451,17 @@ bool LyXLayout::read(LyXLex & lexrc, LyXTextClass const & tclass)
case LT_LABELSTRING: // label string definition case LT_LABELSTRING: // label string definition
if (lexrc.next()) if (lexrc.next())
labelstring_ = lyx::from_ascii(trim(lexrc.getString())); labelstring_ = trim(lexrc.getDocString());
break; break;
case LT_ENDLABELSTRING: // endlabel string definition case LT_ENDLABELSTRING: // endlabel string definition
if (lexrc.next()) if (lexrc.next())
endlabelstring_ = lyx::from_ascii(trim(lexrc.getString())); endlabelstring_ = trim(lexrc.getDocString());
break; break;
case LT_LABELSTRING_APPENDIX: // label string appendix definition case LT_LABELSTRING_APPENDIX: // label string appendix definition
if (lexrc.next()) if (lexrc.next())
labelstring_appendix_ = lyx::from_ascii(trim(lexrc.getString())); labelstring_appendix_ = trim(lexrc.getDocString());
break; break;
case LT_LABELCOUNTER: // name of counter to use case LT_LABELCOUNTER: // name of counter to use

View File

@ -260,7 +260,7 @@ public:
void setParagraph(LCursor & cur, void setParagraph(LCursor & cur,
Spacing const & spacing, Spacing const & spacing,
LyXAlignment align, LyXAlignment align,
std::string const & labelwidthstring, docstring const & labelwidthstring,
bool noindent); bool noindent);
/* these things are for search and replace */ /* these things are for search and replace */

View File

@ -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) char lowercase(char c)
{ {
return char(tolower(c)); return char(tolower(c));

View File

@ -72,6 +72,9 @@ bool isHex(lyx::docstring const & str);
int hexToInt(lyx::docstring const & str); int hexToInt(lyx::docstring const & str);
/// is \p str pure ascii?
bool isAscii(docstring const & str);
/// ///
char lowercase(char c); char lowercase(char c);

View File

@ -352,7 +352,7 @@ void LyXText::setLayout(Buffer const & buffer, pit_type start, pit_type end,
for (pit_type pit = start; pit != end; ++pit) { for (pit_type pit = start; pit != end; ++pit) {
pars_[pit].applyLayout(lyxlayout); pars_[pit].applyLayout(lyxlayout);
if (lyxlayout->margintype == MARGIN_MANUAL) if (lyxlayout->margintype == MARGIN_MANUAL)
pars_[pit].setLabelWidthString(lyxlayout->labelstring()); pars_[pit].setLabelWidthString(buffer.translateLabel(lyxlayout->labelstring()));
} }
} }
@ -604,7 +604,7 @@ docstring LyXText::getStringToIndex(LCursor const & cur)
void LyXText::setParagraph(LCursor & cur, void LyXText::setParagraph(LCursor & cur,
Spacing const & spacing, LyXAlignment align, Spacing const & spacing, LyXAlignment align,
string const & labelwidthstring, bool noindent) docstring const & labelwidthstring, bool noindent)
{ {
BOOST_ASSERT(cur.text()); BOOST_ASSERT(cur.text());
// make sure that the depth behind the selection are restored, too // make sure that the depth behind the selection are restored, too
@ -628,8 +628,7 @@ void LyXText::setParagraph(LCursor & cur,
else else
params.align(align); params.align(align);
} }
// FIXME UNICODE par.setLabelWidthString(labelwidthstring);
par.setLabelWidthString(from_ascii(labelwidthstring));
params.noindent(noindent); params.noindent(noindent);
} }
} }

View File

@ -1411,7 +1411,7 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
} }
setLayout(cur, tclass.defaultLayoutName()); 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()))); insertInset(cur, new InsetFloatList(to_utf8(cmd.argument())));
cur.posRight(); cur.posRight();
} else { } else {
@ -1455,11 +1455,10 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
lex.setStream(is); lex.setStream(is);
ParagraphParameters params; ParagraphParameters params;
params.read(lex); params.read(lex);
// FIXME UNICODE
setParagraph(cur, setParagraph(cur,
params.spacing(), params.spacing(),
params.align(), params.align(),
to_ascii(params.labelWidthString()), params.labelWidthString(),
params.noindent()); params.noindent());
cur.message(_("Paragraph layout set")); cur.message(_("Paragraph layout set"));
break; break;