Zim, Aard: Fix language recognition from three-letter codes

This commit is contained in:
Abs62 2018-12-07 16:18:49 +03:00
parent 1640fb2ff4
commit 6d46fd1529
4 changed files with 3 additions and 17 deletions

View file

@ -1061,12 +1061,12 @@ vector< sptr< Dictionary::Class > > makeDictionaries(
idxHeader.wordCount = wordCount;
if( langFrom.size() == 3)
idxHeader.langFrom = LangCoder::code3toInt( langFrom.c_str() );
idxHeader.langFrom = LangCoder::findIdForLanguageCode3( langFrom.c_str() );
else if( langFrom.size() == 2 )
idxHeader.langFrom = LangCoder::code2toInt( langFrom.c_str() );
if( langTo.size() == 3)
idxHeader.langTo = LangCoder::code3toInt( langTo.c_str() );
idxHeader.langTo = LangCoder::findIdForLanguageCode3( langTo.c_str() );
else if( langTo.size() == 2 )
idxHeader.langTo = LangCoder::code2toInt( langTo.c_str() );

View file

@ -266,18 +266,6 @@ QString LangCoder::intToCode2( quint32 val )
return QString::fromLatin1( code, 2 );
}
quint32 LangCoder::code3toInt(const std::string& code3)
{
if (code3.length() < 2)
return 0;
// this is temporary
char code1 = tolower( code3.at(1) );
char code0 = tolower( code3.at(0) );
return ( ((quint32)code1) << 8 ) + (quint32)code0;
}
quint32 LangCoder::findIdForLanguage( gd::wstring const & lang )
{
gd::wstring langFolded = Folding::apply( lang );

View file

@ -35,8 +35,6 @@ public:
static QString intToCode2( quint32 );
static quint32 code3toInt(const std::string& code3);
/// Finds the id for the given language name, written in english. The search
/// is case- and punctuation insensitive.
static quint32 findIdForLanguage( gd::wstring const & );

2
zim.cc
View file

@ -1674,7 +1674,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries(
idxHeader.langFrom = LangCoder::code2toInt( lang.c_str() );
else
if( lang.size() == 3 )
idxHeader.langFrom = LangCoder::code3toInt( lang.c_str() );
idxHeader.langFrom = LangCoder::findIdForLanguageCode3( lang.c_str() );
idxHeader.langTo = idxHeader.langFrom;
}
}