]> git.lyx.org Git - lyx.git/commitdiff
Don't crash anymore if an .ui file contains unicode labels
authorGeorg Baum <Georg.Baum@post.rwth-aachen.de>
Thu, 23 Nov 2006 16:31:48 +0000 (16:31 +0000)
committerGeorg Baum <Georg.Baum@post.rwth-aachen.de>
Thu, 23 Nov 2006 16:31:48 +0000 (16:31 +0000)
* src/gettext.[Ch]
(translateIfPossible): new function to translate stuff that might
already be in the native language

* src/MenuBackend.C
(Menu::read): Use translateIfPossible for item names and submenu
labels, since the user may have already entered them in his native
language into the .ui file

* src/ToolbarBackend.C
(ToolbarBackend::read): do the same with the tooltip

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@16015 a592a061-630c-0410-9148-cb99ea01b6c8

src/MenuBackend.C
src/ToolbarBackend.C
src/gettext.C
src/gettext.h

index 356c4eb44f986a902f495ca54ce84cccfe953df3..c4f43b76dbdc9180c0dbcaecbe8fb82ddeab114e 100644 (file)
@@ -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 970829b1aa285dd0f0666597eba8a525ce29b2c1..f0471e0d1110c2885d4cfc13d4d2b9c40e98a50e 100644 (file)
@@ -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]
index 925e433363d50ab80972a4c4c70d3f5df129db64..55b2ef80821f79cd55665386522d35198d16868f 100644 (file)
@@ -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 0783413b5eb6bd6a9ac8823201707180de15b480..0624d8be83ef5379ad9824fda22f73f3c9c3f24b 100644 (file)
@@ -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();