Abdelrazak Younes wrote:
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.

Here is an updated patch that I actually tested. It doesn't crash anymore but it doesn't work well because there is a problem with layout files in trunk: I think they are encoded in ISO-8859-1 (latin-1) so ICONV choke on characters with accents. Shouldn't we convert all layout files to utf8?

Abdel.
Index: frontends/qt4/QLToolbar.cpp
===================================================================
--- frontends/qt4/QLToolbar.cpp (revision 19000)
+++ frontends/qt4/QLToolbar.cpp (working copy)
@@ -85,7 +85,7 @@
 {
        TextClass const & tc = getTextClass(owner_);
 
-       QString const & name = qt_(tc[layout]->name());
+       QString const & name = toqstr(translateIfPossible(tc[layout]->name()));
 
        int i = 0;
        for (; i < combo_->count(); ++i) {
@@ -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: frontends/Toolbars.cpp
===================================================================
--- frontends/Toolbars.cpp      (revision 19000)
+++ frontends/Toolbars.cpp      (working copy)
@@ -379,7 +379,7 @@
        for (; it != end; ++it) {
                string const & itname = (*it)->name();
                // Yes, the lyx::to_utf8(_()) is correct
-               if (lyx::to_utf8(_(itname)) == name) {
+               if (lyx::to_utf8(translateIfPossible(itname)) == name) {
                        FuncRequest const func(LFUN_LAYOUT, itname,
                                               FuncRequest::TOOLBAR);
                        lv.dispatch(func);
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();
 

Reply via email to