This patch allows to enter utf8-encoded labelstrings in layout files. This 
makes sense IMO, since labelstrings are no keywords, but only used for GUI 
display.

OK to go in?

BTW, why is layout->labelstring() sometimes used untranslated?
Index: src/support/lstrings.C
===================================================================
--- src/support/lstrings.C	(Revision 15835)
+++ 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 15835)
+++ 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/lyxlayout.C
===================================================================
--- src/lyxlayout.C	(Revision 15835)
+++ 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 15835)
+++ 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>
 
@@ -348,6 +346,18 @@ bool needEnumCounterReset(ParIterator co
 }
 
 
+docstring const translateLabel(Buffer const & buf, docstring const & label)
+{
+	if (support::isAscii(label))
+		// Probably standard layout, try to translate
+		return buf.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;
+}
+
+
 // set the label of a paragraph. This includes the counters.
 void setLabel(Buffer const & buf, ParIterator & it)
 {
@@ -468,8 +478,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(translateLabel(buf, 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 +504,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 = translateLabel(buf, 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(translateLabel(buf, layout->labelstring()));
 }
 
 } // anon namespace
@@ -596,9 +603,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 = translateLabel(buf, appendix ?
+			layout->labelstring_appendix() :
+			layout->labelstring());
 
 	// handle 'inherited level parts' in 'fmt',
 	// i.e. the stuff between '@' in   '@[EMAIL PROTECTED]'

Reply via email to