Abdelrazak Younes wrote:
Charpentier Philippe wrote:
This was working perfectly until 1.4.x. But now the 1.5 version crash
if I want to use one of my layouts (independently of the encoding):
non ASCII characters seems forbidden now for the Style name. As these
names appear in the layout and in the documents, I am afraid that, if
 nothing is done for this I will never be able to use the next
versions of lyx


AFAIU, the problem is that the translation machinery requires that these field are 7 bits ASCII. We have two way of dealing with this problem:

1) provide a python script that converts the layout as good as possible:
 Théorème  -> Theoreme
 Liste_à_puce -> Liste_a_puce

The problem is that it could be done easily for French but maybe not for other languages. Second problem is that I am not sure we have a lyx2lyx equivalent for layoouts, do we?

2) Accept the layout field as is and do not try to translate them.

I think 1) is hard but 2) could be done... If you manage to send a backtrace of the crash, I'll see what I can do.

Disclaimer: I know _nothing_ about layout. So I am probably not aware of problems that could arise with 2).

Here is the proposed patch for solution 2). Note that this assumes that the layout file use the utf8 encoding and not a local one. Please convert your files to utf8 before using this patch.

Please test.

Abdel.
Index: frontends/qt4/QLToolbar.cpp
===================================================================
--- frontends/qt4/QLToolbar.cpp (revision 19000)
+++ frontends/qt4/QLToolbar.cpp (working copy)
@@ -116,7 +116,7 @@
        for (; it != end; ++it) {
                // ignore obsolete entries
                if ((*it)->obsoleted_by().empty())
-                       combo_->addItem(qt_((*it)->name()));
+                       
combo_->addItem(toqstr(translateIfPossible((*it)->name())));
        }
 
        // needed to recalculate size hint
Index: gettext.cpp
===================================================================
--- gettext.cpp (revision 19000)
+++ gettext.cpp (working copy)
@@ -72,4 +72,18 @@
 }
 
 
+docstring const translateIfPossible(string const & name)
+{
+       if (support::isAscii(name))
+               // Probably from a standard configuration file, try to
+               // translate
+               return _(name);
+       else
+               // This must be from a user defined configuration file. We
+               // cannot translate this, since gettext accepts only ascii
+               // keys. We assume that this is UTF8 which might not be true.
+               return from_utf8(name);
+}
+
+
 } // namespace lyx
Index: gettext.h
===================================================================
--- gettext.h   (revision 19000)
+++ gettext.h   (working copy)
@@ -68,6 +68,13 @@
  * language if they come from a file in the personal directory. */
 docstring const translateIfPossible(docstring const & name);
 
+/**
+ * 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(std::string const & name);
+
 ///
 void locale_init();
 
Index: support/lstrings.cpp
===================================================================
--- support/lstrings.cpp        (revision 19000)
+++ support/lstrings.cpp        (working copy)
@@ -254,6 +254,16 @@
 }
 
 
+bool isAscii(string 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)
 {
        BOOST_ASSERT(static_cast<unsigned char>(c) < 0x80);
Index: support/lstrings.h
===================================================================
--- support/lstrings.h  (revision 19000)
+++ support/lstrings.h  (working copy)
@@ -72,6 +72,9 @@
 /// is \p str pure ascii?
 bool isAscii(docstring const & str);
 
+/// is \p str pure ascii?
+bool isAscii(std::string const & str);
+
 /**
  * Changes the case of \p c to lowercase.
  * Don't use this for non-ASCII characters, since it depends on the locale.

Reply via email to