mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-22 10:00:33 +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
a86de5d3c0
commit
7a7b9abf1b
@ -196,10 +196,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
|
||||
@ -48,8 +48,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
|
||||
@ -121,8 +119,6 @@ private:
|
||||
///
|
||||
bool as_babel_options_;
|
||||
///
|
||||
bool translated_;
|
||||
///
|
||||
TranslationMap layoutTranslations_;
|
||||
};
|
||||
|
||||
|
@ -46,6 +46,7 @@
|
||||
#include "support/gettext.h"
|
||||
#include "support/lassert.h"
|
||||
#include "support/lstrings.h"
|
||||
#include "support/Messages.h"
|
||||
#include "support/os.h"
|
||||
#include "support/Package.h"
|
||||
|
||||
@ -2301,9 +2302,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(),
|
||||
|
@ -112,9 +112,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