#7170 simplify the hunspell dictionary lookup; use Language::lang() instead of Language::id() as speller index

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@37727 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Stephan Witt 2011-02-18 11:54:14 +00:00
parent f63a772092
commit e755729f68
3 changed files with 15 additions and 19 deletions

View File

@ -270,14 +270,14 @@ AspellSpeller * AspellChecker::Private::addSpeller(Language const * lang)
initSessionDictionary(m, pd);
}
spellers_[lang->id()] = m;
spellers_[lang->lang()] = m;
return m.e_speller ? to_aspell_speller(m.e_speller) : 0;
}
AspellSpeller * AspellChecker::Private::speller(Language const * lang)
{
Spellers::iterator it = spellers_.find(lang->id());
Spellers::iterator it = spellers_.find(lang->lang());
if (it != spellers_.end())
return to_aspell_speller(it->second.e_speller);
@ -307,7 +307,7 @@ void AspellChecker::Private::remove(WordLangTuple const & word)
if (!pd)
return;
pd->remove(word.word());
Spellers::iterator it = spellers_.find(word.lang()->id());
Spellers::iterator it = spellers_.find(word.lang()->lang());
if (it != spellers_.end()) {
initSessionDictionary(it->second, pd);
}
@ -316,7 +316,7 @@ void AspellChecker::Private::remove(WordLangTuple const & word)
void AspellChecker::Private::insert(WordLangTuple const & word)
{
Spellers::iterator it = spellers_.find(word.lang()->id());
Spellers::iterator it = spellers_.find(word.lang()->lang());
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);
@ -380,7 +380,7 @@ void AspellChecker::insert(WordLangTuple const & word)
void AspellChecker::accept(WordLangTuple const & word)
{
Spellers::iterator it = d->spellers_.find(word.lang()->id());
Spellers::iterator it = d->spellers_.find(word.lang()->lang());
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);

View File

@ -79,6 +79,11 @@ struct HunspellChecker::Private
/// there the aff+dic files lookup will happen
const string dictDirectory(void) const { return "dicts"; }
int maxLookupSelector(void) const { return 3; }
const string HunspellDictionaryName(Language const * lang) {
return lang->variety().empty()
? lang->code()
: lang->code() + "-" + lang->variety();
}
};
@ -139,19 +144,13 @@ bool HunspellChecker::Private::haveDictionary(Language const * lang, string & hp
}
LYXERR(Debug::FILES, "check hunspell path: " << hpath << " for language " << lang);
string h_path = addName(hpath, lang->code() + "-" + lang->variety());
string h_path = addName(hpath, HunspellDictionaryName(lang));
// 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 '-'
// another try with code, '_' replaced by '-'
h_path = addName(hpath, subst(lang->code(), '_', '-'));
if (!haveLanguageFiles(h_path)) {
return false;
@ -178,7 +177,7 @@ bool HunspellChecker::Private::haveDictionary(Language const * lang)
Hunspell * HunspellChecker::Private::speller(Language const * lang)
{
Spellers::iterator it = spellers_.find(lang->id());
Spellers::iterator it = spellers_.find(lang->lang());
if (it != spellers_.end())
return it->second;
@ -189,7 +188,7 @@ Hunspell * HunspellChecker::Private::speller(Language const * lang)
Hunspell * HunspellChecker::Private::addSpeller(Language const * lang,string & path)
{
if (!haveDictionary(lang, path)) {
spellers_[lang->id()] = 0;
spellers_[lang->lang()] = 0;
return 0;
}
@ -197,7 +196,7 @@ Hunspell * HunspellChecker::Private::addSpeller(Language const * lang,string & p
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->id()] = h;
spellers_[lang->lang()] = h;
return h;
}

View File

@ -57,9 +57,6 @@ 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