1
0
Fork 0
mirror of https://git.jami.net/savoirfairelinux/jami-client-qt.git synced 2025-07-01 22:25:26 +02:00

spellchecker: fix greek

greek spell correction wasn't working. this is because  modern greek
is in a special encoding : ISO8859-7. The text in Jami is in utf-8.
Therefore this patch detect the encoding and decode/encode informations
in the relevent encoding between the client and the hunspell library.

GitLab: #2062
Change-Id: Ia33f154e3bf4b84f8337f669df81152ddcd25ec6
This commit is contained in:
pmagnier-slimani 2025-06-09 14:03:37 -04:00 committed by François-Simon Fauteux-Chapleau
parent 3a7850b398
commit e24f3d91e8

View file

@ -37,18 +37,19 @@ bool
SpellChecker::spell(const QString& word)
{
// Encode from Unicode to the encoding used by current dictionary
return hunspell_->spell(word.toStdString()) != 0;
return hunspell_->spell(codec_->fromUnicode(word).toStdString()) != 0;
}
QStringList
SpellChecker::suggest(const QString& word)
{
// Encode from Unicode to the encoding used by current dictionary
std::vector<std::string> numSuggestions = hunspell_->suggest(word.toStdString());
std::vector<std::string> numSuggestions = hunspell_->suggest(
codec_->fromUnicode(word).constData());
QStringList suggestions;
for (size_t i = 0; i < numSuggestions.size(); ++i) {
suggestions << QString::fromStdString(numSuggestions.at(i));
for (const auto& suggestion : numSuggestions) {
suggestions << codec_->toUnicode(suggestion.c_str());
}
return suggestions;
}
@ -77,23 +78,8 @@ SpellChecker::replaceDictionary(const QString& dictionaryPath)
QByteArray dictFilePath = dictFile.toLocal8Bit();
QByteArray affixFilePath = affixFile.toLocal8Bit();
hunspell_.reset(new Hunspell(affixFilePath.constData(), dictFilePath.constData()));
// detect encoding analyzing the SET option in the affix file
encoding_ = "ISO8859-1";
QFile _affixFile(affixFile);
if (_affixFile.open(QIODevice::ReadOnly)) {
QTextStream stream(&_affixFile);
QRegExp enc_detector("^\\s*SET\\s+([A-Z0-9\\-]+)\\s*", Qt::CaseInsensitive);
for (QString line = stream.readLine(); !line.isEmpty(); line = stream.readLine()) {
if (enc_detector.indexIn(line) > -1) {
encoding_ = enc_detector.cap(1);
break;
}
}
_affixFile.close();
}
encoding_ =hunspell_->get_dic_encoding();
codec_ = QTextCodec::codecForName(this->encoding_.toLatin1().constData());
currentDictionaryPath_ = dictionaryPath;
return true;
}