From 83525c9570d61b07a5f5aac94e24a4598817a8c5 Mon Sep 17 00:00:00 2001 From: Georg Baum Date: Thu, 23 Nov 2006 16:31:48 +0000 Subject: [PATCH] Don't crash anymore if an .ui file contains unicode labels * 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 | 4 ++-- src/ToolbarBackend.C | 2 +- src/gettext.C | 16 ++++++++++++++++ src/gettext.h | 7 +++++++ 4 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/MenuBackend.C b/src/MenuBackend.C index 356c4eb44f..c4f43b76db 100644 --- a/src/MenuBackend.C +++ b/src/MenuBackend.C @@ -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, diff --git a/src/ToolbarBackend.C b/src/ToolbarBackend.C index 970829b1aa..f0471e0d11 100644 --- a/src/ToolbarBackend.C +++ b/src/ToolbarBackend.C @@ -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] diff --git a/src/gettext.C b/src/gettext.C index 925e433363..55b2ef8082 100644 --- a/src/gettext.C +++ b/src/gettext.C @@ -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 diff --git a/src/gettext.h b/src/gettext.h index 0783413b5e..0624d8be83 100644 --- a/src/gettext.h +++ b/src/gettext.h @@ -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();