From 53a72a45266feb86c13f47615a4cbb15053f3c63 Mon Sep 17 00:00:00 2001 From: Georg Baum Date: Fri, 3 Dec 2010 17:48:06 +0000 Subject: [PATCH] fix bug #6584 git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@36687 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/Language.cpp | 5 +++++ src/Language.h | 6 +++++- src/frontends/qt4/GuiPrefs.cpp | 12 ++++++++++-- src/support/Messages.cpp | 9 +++++++++ src/support/Messages.h | 2 ++ src/support/filetools.cpp | 2 +- src/support/lstrings.cpp | 7 +++++++ src/support/lstrings.h | 3 +++ 8 files changed, 42 insertions(+), 4 deletions(-) diff --git a/src/Language.cpp b/src/Language.cpp index fe9d56d00a..e588218047 100644 --- a/src/Language.cpp +++ b/src/Language.cpp @@ -22,6 +22,7 @@ #include "support/debug.h" #include "support/FileName.h" #include "support/lstrings.h" +#include "support/Messages.h" using namespace std; using namespace lyx::support; @@ -165,6 +166,10 @@ bool Language::read(Lexer & lex) encoding_ = encodings.fromLyXName("iso8859-1"); LYXERR0("Unknown encoding " << encodingStr_); } + // cache translation status. Calling getMessages() directly in + // PrefLanguage::PrefLanguage() did only work if the gui language + // was set to auto (otherwise all languages would be marked as available). + translated_ = getMessages(code()).available(); return true; } diff --git a/src/Language.h b/src/Language.h index d79ba8f959..073ecdb6d4 100644 --- a/src/Language.h +++ b/src/Language.h @@ -30,7 +30,7 @@ class Lexer; class Language { public: /// - Language() : rightToLeft_(false) {} + Language() : rightToLeft_(false), translated_(false) {} /// LyX language name std::string const & lang() const { return lang_; } /// Babel language name @@ -43,6 +43,8 @@ public: std::string const & display() const { return display_; } /// is this a RTL language? bool rightToLeft() const { return rightToLeft_; } + /// Is an (at least partial) translation of this language available? + bool translated() const { return translated_; } /// default encoding Encoding const * encoding() const { return encoding_; } /// @@ -98,6 +100,8 @@ private: bool internal_enc_; /// bool as_babel_options_; + /// + bool translated_; }; diff --git a/src/frontends/qt4/GuiPrefs.cpp b/src/frontends/qt4/GuiPrefs.cpp index 6ae52de124..434fa92776 100644 --- a/src/frontends/qt4/GuiPrefs.cpp +++ b/src/frontends/qt4/GuiPrefs.cpp @@ -2180,12 +2180,20 @@ PrefLanguage::PrefLanguage(GuiPreferences * form) defaultDecimalPointLE->setInputMask("X; "); defaultDecimalPointLE->setMaxLength(1); - // FIXME: This is wrong, we need filter this list based on the available - // translation. + set added; uiLanguageCO->blockSignals(true); uiLanguageCO->addItem(qt_("Default"), toqstr("auto")); for (int i = 0; i != language_model->rowCount(); ++i) { QModelIndex index = language_model->index(i, 0); + // Filter the list based on the available translation and add + // each language code only once + string const name = fromqstr(index.data(Qt::UserRole).toString()); + Language const * lang = languages.getLanguage(name); + // never remove the currently selected language + if (lang && name != form->rc().gui_language && name != lyxrc.gui_language) + if (!lang->translated() || added.find(lang->code()) != added.end()) + continue; + added.insert(lang->code()); uiLanguageCO->addItem(index.data(Qt::DisplayRole).toString(), index.data(Qt::UserRole).toString()); } diff --git a/src/support/Messages.cpp b/src/support/Messages.cpp index d57f5a4fda..ece2886412 100644 --- a/src/support/Messages.cpp +++ b/src/support/Messages.cpp @@ -14,6 +14,7 @@ #include "support/debug.h" #include "support/docstring.h" #include "support/environment.h" +#include "support/lstrings.h" #include "support/Package.h" #include "support/unicode.h" @@ -121,6 +122,14 @@ void Messages::init() } +bool Messages::available() const +{ + string const test = languageTestString(); + string const trans = to_utf8(get(test)); + return !trans.empty() && trans != test; +} + + docstring const Messages::get(string const & m) const { if (m.empty()) diff --git a/src/support/Messages.h b/src/support/Messages.h index 08500a9044..3b3dce8304 100644 --- a/src/support/Messages.h +++ b/src/support/Messages.h @@ -26,6 +26,8 @@ public: Messages(std::string const & l = std::string()); /// docstring const get(std::string const & msg) const; + /// Is an (at least partial) translation of this language available? + bool available() const; /// static void init(); /// diff --git a/src/support/filetools.cpp b/src/support/filetools.cpp index 82d8766cff..2e8e10f94d 100644 --- a/src/support/filetools.cpp +++ b/src/support/filetools.cpp @@ -268,7 +268,7 @@ FileName const i18nLibFileSearch(string const & dir, string const & name, each po file is able to tell us its name. (JMarc) */ - string lang = to_ascii(_("[[Replace with the code of your language]]")); + string lang = to_ascii(_(languageTestString())); string const language = getEnv("LANGUAGE"); if (!lang.empty() && !language.empty()) lang = language; diff --git a/src/support/lstrings.cpp b/src/support/lstrings.cpp index 7fbe6730f8..9e5301fc00 100644 --- a/src/support/lstrings.cpp +++ b/src/support/lstrings.cpp @@ -15,6 +15,7 @@ #include "support/lstrings.h" #include "support/convert.h" +#include "support/gettext.h" #include "support/qstring_helpers.h" #include "support/textutils.h" @@ -1283,6 +1284,12 @@ int findToken(char const * const str[], string const & search_token) } +string const languageTestString() +{ + return N_("[[Replace with the code of your language]]"); +} + + template<> docstring bformat(docstring const & fmt, int arg1) { diff --git a/src/support/lstrings.h b/src/support/lstrings.h index eca670ea3d..ae68c49df5 100644 --- a/src/support/lstrings.h +++ b/src/support/lstrings.h @@ -283,6 +283,9 @@ docstring const getStringFromVector(std::vector const & vec, /// found, else -1. The last item in \p str must be "". int findToken(char const * const str[], std::string const & search_token); +/// A test string that is supposed to be translated into the gettext code +std::string const languageTestString(); + template docstring bformat(docstring const & fmt, Arg1);