Philippe Charpentier wrote:

> Hi,
> just after the release alpha of lyx-1.5, I compile lyx-1.5svn and test my
> layouts and ui files on it. They are written in ISO-8859 with accented
> characters and work until 1.4.x. My layout and ui files, converted in
> UTF-8 or not, both crash this version of lyx and the tests I did showed
> that only files written in ASCII are accepted.

Do your .ui files work with this patch (requires latest svn to apply
cleanly)?


Georg
Index: src/gettext.C
===================================================================
--- src/gettext.C	(Revision 16008)
+++ src/gettext.C	(Arbeitskopie)
@@ -13,7 +13,9 @@
 
 #include "gettext.h"
 #include "messages.h"
+
 #include "support/environment.h"
+#include "support/lstrings.h"
 
 
 namespace lyx {
@@ -68,4 +70,18 @@ void locale_init()
 #endif
 
 
+docstring const translateIfPossible(docstring const & name)
+{
+	if (support::isAscii(name))
+		// Probably from a standard configuration file, try to
+		// translate
+		return _(to_ascii(name));
+	else
+		// This must be from a user defined configuration file. We
+		// cannot translate this, since gettext accepts only ascii
+		// keys.
+		return name;
+}
+
+
 } // namespace lyx
Index: src/MenuBackend.C
===================================================================
--- src/MenuBackend.C	(Revision 16009)
+++ src/MenuBackend.C	(Arbeitskopie)
@@ -275,7 +275,7 @@ Menu & Menu::read(LyXLex & lex)
 			// fallback to md_item
 		case md_item: {
 			lex.next(true);
-			docstring const name = _(lex.getString());
+			docstring const name = translateIfPossible(lex.getDocString());
 			lex.next(true);
 			string const command = lex.getString();
 			FuncRequest func = lyxaction.lookupFunc(command);
@@ -349,7 +349,7 @@ Menu & Menu::read(LyXLex & lex)
 			// fallback to md_submenu
 		case md_submenu: {
 			lex.next(true);
-			docstring const mlabel = _(lex.getString());
+			docstring const mlabel = translateIfPossible(lex.getDocString());
 			lex.next(true);
 			docstring const mname = lex.getDocString();
 			add(MenuItem(MenuItem::Submenu, mlabel, mname,
Index: src/gettext.h
===================================================================
--- src/gettext.h	(Revision 16008)
+++ src/gettext.h	(Arbeitskopie)
@@ -61,6 +61,13 @@ docstring const _(std::string const &);
 
 #  define N_(str) (str)              // for detecting static strings
 
+/**
+ * Translate \p name if it is possible.
+ * This should be used to translate strings that come from configuration
+ * files like .ui files. These strings could already be in the native
+ * language if they come from a file in the personal directory. */
+docstring const translateIfPossible(docstring const & name);
+
 ///
 void locale_init();
 
Index: src/ToolbarBackend.C
===================================================================
--- src/ToolbarBackend.C	(Revision 16008)
+++ src/ToolbarBackend.C	(Arbeitskopie)
@@ -97,7 +97,7 @@ void ToolbarBackend::read(LyXLex & lex)
 		switch (lex.lex()) {
 		case TO_ADD:
 			if (lex.next(true)) {
-				docstring const tooltip = _(lex.getString());
+				docstring const tooltip = translateIfPossible(lex.getDocString());
 				lex.next(true);
 				string const func_arg = lex.getString();
 				lyxerr[Debug::PARSER]

Reply via email to