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;
}
class Language {
public:
///
- Language() : rightToLeft_(false), translated_(false) {}
+ Language() : rightToLeft_(false) {}
/// LyX language name
std::string const & lang() const { return lang_; }
/// Babel language name
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_; }
/**
* Translate a string from the layout files that appears in the output.
* It takes the translations from lib/layouttranslations instead of
///
bool as_babel_options_;
///
- bool translated_;
- ///
TranslationMap layoutTranslations_;
};
#include "support/foreach.h"
#include "support/gettext.h"
#include "support/lstrings.h"
+#include "support/Messages.h"
#include "support/os.h"
#include "support/Package.h"
// each language code only once
string const name = fromqstr(index.data(Qt::UserRole).toString());
Language const * lang = languages.getLanguage(name);
+ if (!lang)
+ continue;
// 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())
+ if (name != form->rc().gui_language
+ && name != lyxrc.gui_language
+ && (!Messages::available(lang->code())
+ || added.find(lang->code()) != added.end()))
continue;
added.insert(lang->code());
uiLanguageCO->addItem(index.data(Qt::DisplayRole).toString(),
}
-bool Messages::available() const
+bool Messages::available(string const & c)
{
- return !language().empty();
+ static string locale_dir = package().locale_dir().toFilesystemEncoding();
+ string code = c;
+ // this loops at most twice
+ while (true) {
+ string const filen = locale_dir + "/" + code
+ + "/LC_MESSAGES/"PACKAGE".mo";
+ if (FileName(filen).isReadableFile())
+ return true;
+ if (contains(code, '_'))
+ code = token(code, '_', 0);
+ else return false;
+ }
+ return false;
+
}
docstring const get(std::string const & msg) const;
/// What is the language associated with this translation?
std::string language() const;
- /// Is an (at least partial) translation of this language available?
- bool available() const;
+ /// Is an (at least partial) translation of language with code \p c available?
+ static bool available(std::string const & c);
///
static void init();