mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-25 05:55:34 +00:00
Tracking correctly available translations (take 2)
The previous scheme of loading all possible translations and checking whether the work is a bit too much "brute force" and causes problems on Mac OS X (documents loaded with the wrong language). Now there is an helper static method in Messages class that checks whether a readable .mo file exist for the language. There should be an API in gettext for doing that, but alas it is not possible. As a consequence the method Language::translated() has been removed, along with its cache.
This commit is contained in:
parent
ca3cf1f222
commit
2512e1f085
@ -186,10 +186,6 @@ 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;
|
||||
}
|
||||
|
||||
|
@ -31,7 +31,7 @@ class Lexer;
|
||||
class Language {
|
||||
public:
|
||||
///
|
||||
Language() : rightToLeft_(false), translated_(false) {}
|
||||
Language() : rightToLeft_(false) {}
|
||||
/// LyX language name
|
||||
std::string const & lang() const { return lang_; }
|
||||
/// Babel language name
|
||||
@ -44,8 +44,6 @@ 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_; }
|
||||
/**
|
||||
* Translate a string from the layout files that appears in the output.
|
||||
* It takes the translations from lib/layouttranslations instead of
|
||||
@ -113,8 +111,6 @@ private:
|
||||
///
|
||||
bool as_babel_options_;
|
||||
///
|
||||
bool translated_;
|
||||
///
|
||||
TranslationMap layoutTranslations_;
|
||||
};
|
||||
|
||||
|
@ -45,6 +45,7 @@
|
||||
#include "support/foreach.h"
|
||||
#include "support/gettext.h"
|
||||
#include "support/lstrings.h"
|
||||
#include "support/Messages.h"
|
||||
#include "support/os.h"
|
||||
#include "support/Package.h"
|
||||
|
||||
@ -2288,9 +2289,13 @@ PrefLanguage::PrefLanguage(GuiPreferences * form)
|
||||
// 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(),
|
||||
|
@ -115,9 +115,22 @@ string Messages::language() const
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -28,8 +28,8 @@ public:
|
||||
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();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user