git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@36687 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Georg Baum 2010-12-03 17:48:06 +00:00
parent ebd59dbc00
commit 53a72a4526
8 changed files with 42 additions and 4 deletions

View File

@ -22,6 +22,7 @@
#include "support/debug.h" #include "support/debug.h"
#include "support/FileName.h" #include "support/FileName.h"
#include "support/lstrings.h" #include "support/lstrings.h"
#include "support/Messages.h"
using namespace std; using namespace std;
using namespace lyx::support; using namespace lyx::support;
@ -165,6 +166,10 @@ bool Language::read(Lexer & lex)
encoding_ = encodings.fromLyXName("iso8859-1"); encoding_ = encodings.fromLyXName("iso8859-1");
LYXERR0("Unknown encoding " << encodingStr_); 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; return true;
} }

View File

@ -30,7 +30,7 @@ class Lexer;
class Language { class Language {
public: public:
/// ///
Language() : rightToLeft_(false) {} Language() : rightToLeft_(false), translated_(false) {}
/// LyX language name /// LyX language name
std::string const & lang() const { return lang_; } std::string const & lang() const { return lang_; }
/// Babel language name /// Babel language name
@ -43,6 +43,8 @@ public:
std::string const & display() const { return display_; } std::string const & display() const { return display_; }
/// is this a RTL language? /// is this a RTL language?
bool rightToLeft() const { return rightToLeft_; } bool rightToLeft() const { return rightToLeft_; }
/// Is an (at least partial) translation of this language available?
bool translated() const { return translated_; }
/// default encoding /// default encoding
Encoding const * encoding() const { return encoding_; } Encoding const * encoding() const { return encoding_; }
/// ///
@ -98,6 +100,8 @@ private:
bool internal_enc_; bool internal_enc_;
/// ///
bool as_babel_options_; bool as_babel_options_;
///
bool translated_;
}; };

View File

@ -2180,12 +2180,20 @@ PrefLanguage::PrefLanguage(GuiPreferences * form)
defaultDecimalPointLE->setInputMask("X; "); defaultDecimalPointLE->setInputMask("X; ");
defaultDecimalPointLE->setMaxLength(1); defaultDecimalPointLE->setMaxLength(1);
// FIXME: This is wrong, we need filter this list based on the available set<string> added;
// translation.
uiLanguageCO->blockSignals(true); uiLanguageCO->blockSignals(true);
uiLanguageCO->addItem(qt_("Default"), toqstr("auto")); uiLanguageCO->addItem(qt_("Default"), toqstr("auto"));
for (int i = 0; i != language_model->rowCount(); ++i) { for (int i = 0; i != language_model->rowCount(); ++i) {
QModelIndex index = language_model->index(i, 0); 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(), uiLanguageCO->addItem(index.data(Qt::DisplayRole).toString(),
index.data(Qt::UserRole).toString()); index.data(Qt::UserRole).toString());
} }

View File

@ -14,6 +14,7 @@
#include "support/debug.h" #include "support/debug.h"
#include "support/docstring.h" #include "support/docstring.h"
#include "support/environment.h" #include "support/environment.h"
#include "support/lstrings.h"
#include "support/Package.h" #include "support/Package.h"
#include "support/unicode.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 docstring const Messages::get(string const & m) const
{ {
if (m.empty()) if (m.empty())

View File

@ -26,6 +26,8 @@ public:
Messages(std::string const & l = std::string()); Messages(std::string const & l = std::string());
/// ///
docstring const get(std::string const & msg) const; docstring const get(std::string const & msg) const;
/// Is an (at least partial) translation of this language available?
bool available() const;
/// ///
static void init(); static void init();
/// ///

View File

@ -268,7 +268,7 @@ FileName const i18nLibFileSearch(string const & dir, string const & name,
each po file is able to tell us its name. (JMarc) 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"); string const language = getEnv("LANGUAGE");
if (!lang.empty() && !language.empty()) if (!lang.empty() && !language.empty())
lang = language; lang = language;

View File

@ -15,6 +15,7 @@
#include "support/lstrings.h" #include "support/lstrings.h"
#include "support/convert.h" #include "support/convert.h"
#include "support/gettext.h"
#include "support/qstring_helpers.h" #include "support/qstring_helpers.h"
#include "support/textutils.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<> template<>
docstring bformat(docstring const & fmt, int arg1) docstring bformat(docstring const & fmt, int arg1)
{ {

View File

@ -283,6 +283,9 @@ docstring const getStringFromVector(std::vector<docstring> const & vec,
/// found, else -1. The last item in \p str must be "". /// found, else -1. The last item in \p str must be "".
int findToken(char const * const str[], std::string const & search_token); 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 <class Arg1> template <class Arg1>
docstring bformat(docstring const & fmt, Arg1); docstring bformat(docstring const & fmt, Arg1);