mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-22 18:08:10 +00:00
#7170 add id() method for language; add variety of language to hunspell dictionary lookup; use dicts as subdirectory to search for in system_support and user_support directories
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@37716 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
e2329914ec
commit
4ba2c362cb
@ -61,9 +61,6 @@ struct AspellChecker::Private
|
||||
///
|
||||
AspellSpeller * speller(Language const * lang);
|
||||
|
||||
/// create a unique ID from lang code and variety
|
||||
string const spellerID(Language const * lang);
|
||||
|
||||
bool isValidDictionary(AspellConfig * config,
|
||||
string const & lang, string const & variety);
|
||||
bool checkAspellData(AspellConfig * config,
|
||||
@ -88,7 +85,7 @@ struct AspellChecker::Private
|
||||
|
||||
/// the location below system/user directory
|
||||
/// there the rws files lookup will happen
|
||||
const string dictDirectory(void) { return "dict"; }
|
||||
const string dictDirectory(void) { return "dicts"; }
|
||||
/// there the dat+cmap files lookup will happen
|
||||
const string dataDirectory(void) { return "data"; }
|
||||
/// os package directory constants
|
||||
@ -273,14 +270,14 @@ AspellSpeller * AspellChecker::Private::addSpeller(Language const * lang)
|
||||
initSessionDictionary(m, pd);
|
||||
}
|
||||
|
||||
spellers_[spellerID(lang)] = m;
|
||||
spellers_[lang->id()] = m;
|
||||
return m.e_speller ? to_aspell_speller(m.e_speller) : 0;
|
||||
}
|
||||
|
||||
|
||||
AspellSpeller * AspellChecker::Private::speller(Language const * lang)
|
||||
{
|
||||
Spellers::iterator it = spellers_.find(spellerID(lang));
|
||||
Spellers::iterator it = spellers_.find(lang->id());
|
||||
if (it != spellers_.end())
|
||||
return to_aspell_speller(it->second.e_speller);
|
||||
|
||||
@ -288,12 +285,6 @@ AspellSpeller * AspellChecker::Private::speller(Language const * lang)
|
||||
}
|
||||
|
||||
|
||||
string const AspellChecker::Private::spellerID(Language const * lang)
|
||||
{
|
||||
return lang->code() + "-" + lang->variety();
|
||||
}
|
||||
|
||||
|
||||
SpellChecker::Result AspellChecker::Private::check(
|
||||
AspellSpeller * m, string const & word)
|
||||
const
|
||||
@ -316,7 +307,7 @@ void AspellChecker::Private::remove(WordLangTuple const & word)
|
||||
if (!pd)
|
||||
return;
|
||||
pd->remove(word.word());
|
||||
Spellers::iterator it = spellers_.find(spellerID(word.lang()));
|
||||
Spellers::iterator it = spellers_.find(word.lang()->id());
|
||||
if (it != spellers_.end()) {
|
||||
initSessionDictionary(it->second, pd);
|
||||
}
|
||||
@ -325,7 +316,7 @@ void AspellChecker::Private::remove(WordLangTuple const & word)
|
||||
|
||||
void AspellChecker::Private::insert(WordLangTuple const & word)
|
||||
{
|
||||
Spellers::iterator it = spellers_.find(spellerID(word.lang()));
|
||||
Spellers::iterator it = spellers_.find(word.lang()->id());
|
||||
if (it != spellers_.end()) {
|
||||
AspellSpeller * speller = to_aspell_speller(it->second.e_speller);
|
||||
aspell_speller_add_to_session(speller, to_utf8(word.word()).c_str(), -1);
|
||||
@ -389,7 +380,7 @@ void AspellChecker::insert(WordLangTuple const & word)
|
||||
|
||||
void AspellChecker::accept(WordLangTuple const & word)
|
||||
{
|
||||
Spellers::iterator it = d->spellers_.find(d->spellerID(word.lang()));
|
||||
Spellers::iterator it = d->spellers_.find(word.lang()->id());
|
||||
if (it != d->spellers_.end()) {
|
||||
AspellSpeller * speller = to_aspell_speller(it->second.e_speller);
|
||||
aspell_speller_add_to_session(speller, to_utf8(word.word()).c_str(), -1);
|
||||
|
@ -57,9 +57,9 @@ struct HunspellChecker::Private
|
||||
|
||||
const string dictPath(int selector);
|
||||
bool haveLanguageFiles(string const & hpath);
|
||||
bool haveDictionary(string const & lang, string & hpath);
|
||||
bool haveDictionary(string const & lang);
|
||||
Hunspell * addSpeller(string const & lang, string & hpath);
|
||||
bool haveDictionary(Language const * lang, string & hpath);
|
||||
bool haveDictionary(Language const * lang);
|
||||
Hunspell * addSpeller(Language const * lang, string & hpath);
|
||||
Hunspell * addSpeller(Language const * lang);
|
||||
Hunspell * speller(Language const * lang);
|
||||
/// ignored words
|
||||
@ -77,7 +77,7 @@ struct HunspellChecker::Private
|
||||
|
||||
/// the location below system/user directory
|
||||
/// there the aff+dic files lookup will happen
|
||||
const string dictDirectory(void) const { return "dict"; }
|
||||
const string dictDirectory(void) const { return "dicts"; }
|
||||
int maxLookupSelector(void) const { return 3; }
|
||||
};
|
||||
|
||||
@ -132,43 +132,53 @@ const string HunspellChecker::Private::dictPath(int selector)
|
||||
}
|
||||
|
||||
|
||||
bool HunspellChecker::Private::haveDictionary(string const & lang, string & hpath)
|
||||
bool HunspellChecker::Private::haveDictionary(Language const * lang, string & hpath)
|
||||
{
|
||||
if (hpath.empty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
LYXERR(Debug::FILES, "check hunspell path: " << hpath << " for language " << lang);
|
||||
string h_path = addName(hpath, lang);
|
||||
string h_path = addName(hpath, lang->code() + "-" + lang->variety());
|
||||
// first we try lang code+variety
|
||||
if (!lang->variety().empty() && haveLanguageFiles(h_path)) {
|
||||
hpath = h_path;
|
||||
return true;
|
||||
}
|
||||
// next we try lang code only
|
||||
h_path = addName(hpath, lang->code());
|
||||
if (haveLanguageFiles(h_path)) {
|
||||
hpath = h_path;
|
||||
return true;
|
||||
}
|
||||
// last try with '_' replaced by '-'
|
||||
h_path = addName(hpath, subst(lang->code(), '_', '-'));
|
||||
if (!haveLanguageFiles(h_path)) {
|
||||
// try with '_' replaced by '-'
|
||||
h_path = addName(hpath, subst(lang, '_', '-'));
|
||||
if (!haveLanguageFiles(h_path)) {
|
||||
// FIXME: We should indicate somehow that this language is not
|
||||
// supported, probably by popping a warning. But we'll need to
|
||||
// remember which warnings we've issued.
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
hpath = h_path;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool HunspellChecker::Private::haveDictionary(string const & lang)
|
||||
bool HunspellChecker::Private::haveDictionary(Language const * lang)
|
||||
{
|
||||
bool result = false;
|
||||
for ( int p = 0; !result && p < maxLookupSelector(); p++ ) {
|
||||
string lpath = dictPath(p);
|
||||
result = haveDictionary(lang, lpath);
|
||||
}
|
||||
// FIXME: if result is false...
|
||||
// we should indicate somehow that this language is not
|
||||
// supported, probably by popping a warning. But we'll need to
|
||||
// remember which warnings we've issued.
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
Hunspell * HunspellChecker::Private::speller(Language const * lang)
|
||||
{
|
||||
Spellers::iterator it = spellers_.find(lang->code());
|
||||
Spellers::iterator it = spellers_.find(lang->id());
|
||||
if (it != spellers_.end())
|
||||
return it->second;
|
||||
|
||||
@ -176,10 +186,10 @@ Hunspell * HunspellChecker::Private::speller(Language const * lang)
|
||||
}
|
||||
|
||||
|
||||
Hunspell * HunspellChecker::Private::addSpeller(string const & lang,string & path)
|
||||
Hunspell * HunspellChecker::Private::addSpeller(Language const * lang,string & path)
|
||||
{
|
||||
if (!haveDictionary(lang, path)) {
|
||||
spellers_[lang] = 0;
|
||||
spellers_[lang->id()] = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -187,7 +197,7 @@ Hunspell * HunspellChecker::Private::addSpeller(string const & lang,string & pat
|
||||
FileName const dict(path + ".dic");
|
||||
Hunspell * h = new Hunspell(affix.absFileName().c_str(), dict.absFileName().c_str());
|
||||
LYXERR(Debug::FILES, "Hunspell speller for langage " << lang << " at " << dict << " found");
|
||||
spellers_[lang] = h;
|
||||
spellers_[lang->id()] = h;
|
||||
return h;
|
||||
}
|
||||
|
||||
@ -197,7 +207,7 @@ Hunspell * HunspellChecker::Private::addSpeller(Language const * lang)
|
||||
Hunspell * h = 0;
|
||||
for ( int p = 0; p < maxLookupSelector() && 0 == h; p++ ) {
|
||||
string lpath = dictPath(p);
|
||||
h = addSpeller(lang->code(), lpath);
|
||||
h = addSpeller(lang, lpath);
|
||||
}
|
||||
if (0 != h) {
|
||||
string const encoding = h->get_dic_encoding();
|
||||
@ -360,7 +370,7 @@ bool HunspellChecker::hasDictionary(Language const * lang) const
|
||||
{
|
||||
if (!lang)
|
||||
return false;
|
||||
return (d->haveDictionary(lang->code()));
|
||||
return (d->haveDictionary(lang));
|
||||
}
|
||||
|
||||
|
||||
|
@ -57,6 +57,9 @@ public:
|
||||
std::string const & variety() const { return variety_; }
|
||||
/// set variety (needed for rc.spellchecker_alt_lang)
|
||||
void setVariety(std::string const v) { variety_ = v; }
|
||||
/// create a unique ID from lang code and variety
|
||||
std::string const id() const {
|
||||
return variety_.empty() ? code_ : code_ + "-" + variety_; }
|
||||
/// preamble settings after babel was called
|
||||
std::string const & babel_postsettings() const { return babel_postsettings_; }
|
||||
/// preamble settings before babel is called
|
||||
|
Loading…
Reference in New Issue
Block a user