From 5cd8f6c3c3cffe366b24a9ec43a2fedfaa13d219 Mon Sep 17 00:00:00 2001 From: Xu Jiyong Date: Wed, 24 Jan 2024 09:29:48 +0800 Subject: [PATCH 1/5] opt: add the language variant option for wikipedia dictionaries --- locale/crowdin.ts | 4 ++++ src/config.cc | 33 +++++++++++++++++++++++---------- src/config.hh | 8 +++++--- src/dict/mediawiki.cc | 18 ++++++++++++++---- src/dict/sources.cc | 13 ++++++++++++- 5 files changed, 58 insertions(+), 18 deletions(-) diff --git a/locale/crowdin.ts b/locale/crowdin.ts index 28a1375c2..51510c92e 100644 --- a/locale/crowdin.ts +++ b/locale/crowdin.ts @@ -2755,6 +2755,10 @@ To find '*', '?', '[', ']' symbols use & Icon 图标 + + Language Variant + 语言变体 + MultimediaAudioPlayer diff --git a/src/config.cc b/src/config.cc index f103d9b2f..0dadca997 100644 --- a/src/config.cc +++ b/src/config.cc @@ -332,28 +332,36 @@ MediaWikis makeDefaultMediaWikis( bool enable ) MediaWikis mw; mw.push_back( - MediaWiki( "ae6f89aac7151829681b85f035d54e48", "English Wikipedia", "https://en.wikipedia.org/w", enable, "" ) ); + MediaWiki( "ae6f89aac7151829681b85f035d54e48", "English Wikipedia", "https://en.wikipedia.org/w", enable, "", "" ) ); mw.push_back( - MediaWiki( "affcf9678e7bfe701c9b071f97eccba3", "English Wiktionary", "https://en.wiktionary.org/w", enable, "" ) ); + MediaWiki( "affcf9678e7bfe701c9b071f97eccba3", "English Wiktionary", "https://en.wiktionary.org/w", enable, "", "" ) ); mw.push_back( - MediaWiki( "8e0c1c2b6821dab8bdba8eb869ca7176", "Russian Wikipedia", "https://ru.wikipedia.org/w", false, "" ) ); + MediaWiki( "8e0c1c2b6821dab8bdba8eb869ca7176", "Russian Wikipedia", "https://ru.wikipedia.org/w", false, "", "" ) ); mw.push_back( - MediaWiki( "b09947600ae3902654f8ad4567ae8567", "Russian Wiktionary", "https://ru.wiktionary.org/w", false, "" ) ); + MediaWiki( "b09947600ae3902654f8ad4567ae8567", "Russian Wiktionary", "https://ru.wiktionary.org/w", false, "", "" ) ); mw.push_back( - MediaWiki( "a8a66331a1242ca2aeb0b4aed361c41d", "German Wikipedia", "https://de.wikipedia.org/w", false, "" ) ); + MediaWiki( "a8a66331a1242ca2aeb0b4aed361c41d", "German Wikipedia", "https://de.wikipedia.org/w", false, "", "" ) ); mw.push_back( - MediaWiki( "21c64bca5ec10ba17ff19f3066bc962a", "German Wiktionary", "https://de.wiktionary.org/w", false, "" ) ); + MediaWiki( "21c64bca5ec10ba17ff19f3066bc962a", "German Wiktionary", "https://de.wiktionary.org/w", false, "", "" ) ); mw.push_back( - MediaWiki( "96957cb2ad73a20c7a1d561fc83c253a", "Portuguese Wikipedia", "https://pt.wikipedia.org/w", false, "" ) ); + MediaWiki( "96957cb2ad73a20c7a1d561fc83c253a", "Portuguese Wikipedia", "https://pt.wikipedia.org/w", false, "", "" ) ); mw.push_back( MediaWiki( "ed4c3929196afdd93cc08b9a903aad6a", "Portuguese Wiktionary", "https://pt.wiktionary.org/w", false, - "" ) ); + "", "" ) ); mw.push_back( - MediaWiki( "f3b4ec8531e52ddf5b10d21e4577a7a2", "Greek Wikipedia", "https://el.wikipedia.org/w", false, "" ) ); + MediaWiki( "f3b4ec8531e52ddf5b10d21e4577a7a2", "Greek Wikipedia", "https://el.wikipedia.org/w", false, "" , "" ) ); mw.push_back( - MediaWiki( "5d45232075d06e002dea72fe3e137da1", "Greek Wiktionary", "https://el.wiktionary.org/w", false, "" ) ); + MediaWiki( "5d45232075d06e002dea72fe3e137da1", "Greek Wiktionary", "https://el.wiktionary.org/w", false, "" , "" ) ); + mw.push_back( + MediaWiki( "c015d60c4949ad75b5b7069c2ff6dc2c", "traditional Chinese Wikipedia", "http://zh.wikipedia.org/w", false, "" , "zh-hant" ) ); + mw.push_back( + MediaWiki( "d50828ad6e115bc9d3421b6821543108", "traditional Chinese Wiktionary", "http://zh.wiktionary.org/w", false, "" , "zh-hant" ) ); + mw.push_back( + MediaWiki( "438b17b48cbda1a22d317fea37ec3110", "Simplified Chinese Wikipedia", "https://zh.wikipedia.org/w", false, "" , "zh-hans" ) ); + mw.push_back( + MediaWiki( "b68b9fb71b5a8c766cc7a5ea8237fc6b", "Simplified Chinese Wiktionary", "https://zh.wiktionary.org/w", false, "" , "zh-hans" ) ); return mw; } @@ -760,6 +768,7 @@ Class load() w.url = mw.attribute( "url" ); w.enabled = ( mw.attribute( "enabled" ) == "1" ); w.icon = mw.attribute( "icon" ); + w.lang = mw.attribute( "lang" ); c.mediawikis.push_back( w ); } @@ -1527,6 +1536,10 @@ void save( Class const & c ) QDomAttr icon = dd.createAttribute( "icon" ); icon.setValue( mediawiki.icon ); mw.setAttributeNode( icon ); + + QDomAttr lang = dd.createAttribute( "lang" ); + lang.setValue( mediawiki.lang ); + mw.setAttributeNode( lang ); } } diff --git a/src/config.hh b/src/config.hh index a809f2724..4b9d72729 100644 --- a/src/config.hh +++ b/src/config.hh @@ -455,24 +455,26 @@ struct MediaWiki QString id, name, url; bool enabled; QString icon; + QString lang; MediaWiki(): enabled( false ) { } - MediaWiki( QString const & id_, QString const & name_, QString const & url_, bool enabled_, QString const & icon_ ): + MediaWiki( QString const & id_, QString const & name_, QString const & url_, bool enabled_, QString const & icon_, QString const & lang_ ): id( id_ ), name( name_ ), url( url_ ), enabled( enabled_ ), - icon( icon_ ) + icon( icon_ ), + lang( lang_ ) { } bool operator==( MediaWiki const & other ) const { - return id == other.id && name == other.name && url == other.url && enabled == other.enabled && icon == other.icon; + return id == other.id && name == other.name && url == other.url && enabled == other.enabled && icon == other.icon && lang == other.lang; } }; diff --git a/src/dict/mediawiki.cc b/src/dict/mediawiki.cc index d7ccdf431..81905ba5f 100644 --- a/src/dict/mediawiki.cc +++ b/src/dict/mediawiki.cc @@ -26,7 +26,7 @@ namespace { class MediaWikiDictionary: public Dictionary::Class { string name; - QString url, icon; + QString url, icon, lang; QNetworkAccessManager & netMgr; quint32 langId; @@ -36,11 +36,13 @@ class MediaWikiDictionary: public Dictionary::Class string const & name_, QString const & url_, QString const & icon_, + QString const & lang_, QNetworkAccessManager & netMgr_ ): Dictionary::Class( id, vector< string >() ), name( name_ ), url( url_ ), icon( icon_ ), + lang( lang_ ), netMgr( netMgr_ ), langId( 0 ) { @@ -132,7 +134,7 @@ class MediaWikiWordSearchRequest: public MediaWikiWordSearchRequestSlots public: - MediaWikiWordSearchRequest( wstring const &, QString const & url, QNetworkAccessManager & mgr ); + MediaWikiWordSearchRequest( wstring const &, QString const & url, QString const & lang, QNetworkAccessManager & mgr ); ~MediaWikiWordSearchRequest(); @@ -145,6 +147,7 @@ class MediaWikiWordSearchRequest: public MediaWikiWordSearchRequestSlots MediaWikiWordSearchRequest::MediaWikiWordSearchRequest( wstring const & str, QString const & url, + QString const & lang, QNetworkAccessManager & mgr ): isCancelling( false ) { @@ -154,6 +157,7 @@ MediaWikiWordSearchRequest::MediaWikiWordSearchRequest( wstring const & str, GlobalBroadcaster::instance()->addWhitelist( reqUrl.host() ); Utils::Url::addQueryItem( reqUrl, "apprefix", QString::fromStdU32String( str ).replace( '+', "%2B" ) ); + Utils::Url::addQueryItem( reqUrl, "lang", lang ); QNetworkRequest req( reqUrl ); //millseconds. @@ -376,12 +380,14 @@ class MediaWikiArticleRequest: public MediaWikiDataRequestSlots typedef std::list< std::pair< QNetworkReply *, bool > > NetReplies; NetReplies netReplies; QString url; + QString lang; public: MediaWikiArticleRequest( wstring const & word, vector< wstring > const & alts, QString const & url, + QString const & lang, QNetworkAccessManager & mgr, Class * dictPtr_ ); @@ -425,9 +431,11 @@ void MediaWikiArticleRequest::cancel() MediaWikiArticleRequest::MediaWikiArticleRequest( wstring const & str, vector< wstring > const & alts, QString const & url_, + QString const & lang_, QNetworkAccessManager & mgr, Class * dictPtr_ ): url( url_ ), + lang( lang_ ), dictPtr( dictPtr_ ) { connect( &mgr, @@ -449,6 +457,7 @@ void MediaWikiArticleRequest::addQuery( QNetworkAccessManager & mgr, wstring con QUrl reqUrl( url + "/api.php?action=parse&prop=text|revid|sections&format=xml&redirects" ); Utils::Url::addQueryItem( reqUrl, "page", QString::fromStdU32String( str ).replace( '+', "%2B" ) ); + Utils::Url::addQueryItem( reqUrl, "variant", lang ); QNetworkRequest req( reqUrl ); //millseconds. req.setTransferTimeout( 3000 ); @@ -690,7 +699,7 @@ sptr< WordSearchRequest > MediaWikiDictionary::prefixMatch( wstring const & word return std::make_shared< WordSearchRequestInstant >(); } else - return std::make_shared< MediaWikiWordSearchRequest >( word, url, netMgr ); + return std::make_shared< MediaWikiWordSearchRequest >( word, url, lang, netMgr ); } sptr< DataRequest > @@ -703,7 +712,7 @@ MediaWikiDictionary::getArticle( wstring const & word, vector< wstring > const & return std::make_shared< DataRequestInstant >( false ); } else - return std::make_shared< MediaWikiArticleRequest >( word, alts, url, netMgr, this ); + return std::make_shared< MediaWikiArticleRequest >( word, alts, url, lang, netMgr, this ); } } // namespace @@ -720,6 +729,7 @@ makeDictionaries( Dictionary::Initializing &, Config::MediaWikis const & wikis, wiki.name.toUtf8().data(), wiki.url, wiki.icon, + wiki.lang, mgr ) ); } diff --git a/src/dict/sources.cc b/src/dict/sources.cc index 3acdec4c4..10ffd2faa 100644 --- a/src/dict/sources.cc +++ b/src/dict/sources.cc @@ -49,6 +49,7 @@ Sources::Sources( QWidget * parent, Config::Class const & cfg ): ui.mediaWikis->resizeColumnToContents( 1 ); ui.mediaWikis->resizeColumnToContents( 2 ); ui.mediaWikis->resizeColumnToContents( 3 ); + ui.mediaWikis->resizeColumnToContents( 4 ); ui.webSites->setTabKeyNavigation( true ); ui.webSites->setModel( &webSitesModel ); @@ -429,6 +430,8 @@ void MediaWikisModel::addNewWiki() w.url = "http://"; + w.lang = ""; + beginInsertRows( QModelIndex(), mediawikis.size(), mediawikis.size() ); mediawikis.push_back( w ); endInsertRows(); @@ -471,7 +474,7 @@ int MediaWikisModel::columnCount( QModelIndex const & parent ) const if ( parent.isValid() ) return 0; else - return 4; + return 5; } QVariant MediaWikisModel::headerData( int section, Qt::Orientation /*orientation*/, int role ) const @@ -486,6 +489,8 @@ QVariant MediaWikisModel::headerData( int section, Qt::Orientation /*orientation return tr( "Address" ); case 3: return tr( "Icon" ); + case 4: + return tr( "Language Variant" ); default: return QVariant(); } @@ -506,6 +511,8 @@ QVariant MediaWikisModel::data( QModelIndex const & index, int role ) const return mediawikis[ index.row() ].url; case 3: return mediawikis[ index.row() ].icon; + case 4: + return mediawikis[ index.row() ].lang; default: return QVariant(); } @@ -547,6 +554,10 @@ bool MediaWikisModel::setData( QModelIndex const & index, const QVariant & value mediawikis[ index.row() ].icon = value.toString(); dataChanged( index, index ); return true; + case 4: + mediawikis[ index.row() ].lang = value.toString(); + dataChanged( index, index ); + return true; default: return false; } From 2153233e9176819191a6455ef31398945d927091 Mon Sep 17 00:00:00 2001 From: Xu Jiyong Date: Wed, 24 Jan 2024 10:50:32 +0800 Subject: [PATCH 2/5] fix:default value for 'lang_' parameter --- src/config.cc | 20 ++++++++++---------- src/config.hh | 2 +- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/config.cc b/src/config.cc index 0dadca997..5c1243aeb 100644 --- a/src/config.cc +++ b/src/config.cc @@ -332,28 +332,28 @@ MediaWikis makeDefaultMediaWikis( bool enable ) MediaWikis mw; mw.push_back( - MediaWiki( "ae6f89aac7151829681b85f035d54e48", "English Wikipedia", "https://en.wikipedia.org/w", enable, "", "" ) ); + MediaWiki( "ae6f89aac7151829681b85f035d54e48", "English Wikipedia", "https://en.wikipedia.org/w", enable, "" ) ); mw.push_back( - MediaWiki( "affcf9678e7bfe701c9b071f97eccba3", "English Wiktionary", "https://en.wiktionary.org/w", enable, "", "" ) ); + MediaWiki( "affcf9678e7bfe701c9b071f97eccba3", "English Wiktionary", "https://en.wiktionary.org/w", enable, "" ) ); mw.push_back( - MediaWiki( "8e0c1c2b6821dab8bdba8eb869ca7176", "Russian Wikipedia", "https://ru.wikipedia.org/w", false, "", "" ) ); + MediaWiki( "8e0c1c2b6821dab8bdba8eb869ca7176", "Russian Wikipedia", "https://ru.wikipedia.org/w", false, "" ) ); mw.push_back( - MediaWiki( "b09947600ae3902654f8ad4567ae8567", "Russian Wiktionary", "https://ru.wiktionary.org/w", false, "", "" ) ); + MediaWiki( "b09947600ae3902654f8ad4567ae8567", "Russian Wiktionary", "https://ru.wiktionary.org/w", false, "" ) ); mw.push_back( - MediaWiki( "a8a66331a1242ca2aeb0b4aed361c41d", "German Wikipedia", "https://de.wikipedia.org/w", false, "", "" ) ); + MediaWiki( "a8a66331a1242ca2aeb0b4aed361c41d", "German Wikipedia", "https://de.wikipedia.org/w", false, "" ) ); mw.push_back( - MediaWiki( "21c64bca5ec10ba17ff19f3066bc962a", "German Wiktionary", "https://de.wiktionary.org/w", false, "", "" ) ); + MediaWiki( "21c64bca5ec10ba17ff19f3066bc962a", "German Wiktionary", "https://de.wiktionary.org/w", false, "" ) ); mw.push_back( - MediaWiki( "96957cb2ad73a20c7a1d561fc83c253a", "Portuguese Wikipedia", "https://pt.wikipedia.org/w", false, "", "" ) ); + MediaWiki( "96957cb2ad73a20c7a1d561fc83c253a", "Portuguese Wikipedia", "https://pt.wikipedia.org/w", false, "" ) ); mw.push_back( MediaWiki( "ed4c3929196afdd93cc08b9a903aad6a", "Portuguese Wiktionary", "https://pt.wiktionary.org/w", false, - "", "" ) ); + "" ) ); mw.push_back( - MediaWiki( "f3b4ec8531e52ddf5b10d21e4577a7a2", "Greek Wikipedia", "https://el.wikipedia.org/w", false, "" , "" ) ); + MediaWiki( "f3b4ec8531e52ddf5b10d21e4577a7a2", "Greek Wikipedia", "https://el.wikipedia.org/w", false, "" ) ); mw.push_back( - MediaWiki( "5d45232075d06e002dea72fe3e137da1", "Greek Wiktionary", "https://el.wiktionary.org/w", false, "" , "" ) ); + MediaWiki( "5d45232075d06e002dea72fe3e137da1", "Greek Wiktionary", "https://el.wiktionary.org/w", false, "" ) ); mw.push_back( MediaWiki( "c015d60c4949ad75b5b7069c2ff6dc2c", "traditional Chinese Wikipedia", "http://zh.wikipedia.org/w", false, "" , "zh-hant" ) ); mw.push_back( diff --git a/src/config.hh b/src/config.hh index 4b9d72729..da27130cd 100644 --- a/src/config.hh +++ b/src/config.hh @@ -462,7 +462,7 @@ struct MediaWiki { } - MediaWiki( QString const & id_, QString const & name_, QString const & url_, bool enabled_, QString const & icon_, QString const & lang_ ): + MediaWiki( QString const & id_, QString const & name_, QString const & url_, bool enabled_, QString const & icon_, QString const & lang_ = "" ): id( id_ ), name( name_ ), url( url_ ), From 7a05b63baec5559a3c330a94e821b6e857dbc84e Mon Sep 17 00:00:00 2001 From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com> Date: Wed, 24 Jan 2024 14:57:38 +0000 Subject: [PATCH 3/5] [autofix.ci] apply automated fixes --- src/config.cc | 32 ++++++++++++++++++++++++-------- src/config.hh | 10 ++++++++-- 2 files changed, 32 insertions(+), 10 deletions(-) diff --git a/src/config.cc b/src/config.cc index 5c1243aeb..922f55534 100644 --- a/src/config.cc +++ b/src/config.cc @@ -354,14 +354,30 @@ MediaWikis makeDefaultMediaWikis( bool enable ) MediaWiki( "f3b4ec8531e52ddf5b10d21e4577a7a2", "Greek Wikipedia", "https://el.wikipedia.org/w", false, "" ) ); mw.push_back( MediaWiki( "5d45232075d06e002dea72fe3e137da1", "Greek Wiktionary", "https://el.wiktionary.org/w", false, "" ) ); - mw.push_back( - MediaWiki( "c015d60c4949ad75b5b7069c2ff6dc2c", "traditional Chinese Wikipedia", "http://zh.wikipedia.org/w", false, "" , "zh-hant" ) ); - mw.push_back( - MediaWiki( "d50828ad6e115bc9d3421b6821543108", "traditional Chinese Wiktionary", "http://zh.wiktionary.org/w", false, "" , "zh-hant" ) ); - mw.push_back( - MediaWiki( "438b17b48cbda1a22d317fea37ec3110", "Simplified Chinese Wikipedia", "https://zh.wikipedia.org/w", false, "" , "zh-hans" ) ); - mw.push_back( - MediaWiki( "b68b9fb71b5a8c766cc7a5ea8237fc6b", "Simplified Chinese Wiktionary", "https://zh.wiktionary.org/w", false, "" , "zh-hans" ) ); + mw.push_back( MediaWiki( "c015d60c4949ad75b5b7069c2ff6dc2c", + "traditional Chinese Wikipedia", + "http://zh.wikipedia.org/w", + false, + "", + "zh-hant" ) ); + mw.push_back( MediaWiki( "d50828ad6e115bc9d3421b6821543108", + "traditional Chinese Wiktionary", + "http://zh.wiktionary.org/w", + false, + "", + "zh-hant" ) ); + mw.push_back( MediaWiki( "438b17b48cbda1a22d317fea37ec3110", + "Simplified Chinese Wikipedia", + "https://zh.wikipedia.org/w", + false, + "", + "zh-hans" ) ); + mw.push_back( MediaWiki( "b68b9fb71b5a8c766cc7a5ea8237fc6b", + "Simplified Chinese Wiktionary", + "https://zh.wiktionary.org/w", + false, + "", + "zh-hans" ) ); return mw; } diff --git a/src/config.hh b/src/config.hh index da27130cd..ed057c57a 100644 --- a/src/config.hh +++ b/src/config.hh @@ -462,7 +462,12 @@ struct MediaWiki { } - MediaWiki( QString const & id_, QString const & name_, QString const & url_, bool enabled_, QString const & icon_, QString const & lang_ = "" ): + MediaWiki( QString const & id_, + QString const & name_, + QString const & url_, + bool enabled_, + QString const & icon_, + QString const & lang_ = "" ): id( id_ ), name( name_ ), url( url_ ), @@ -474,7 +479,8 @@ struct MediaWiki bool operator==( MediaWiki const & other ) const { - return id == other.id && name == other.name && url == other.url && enabled == other.enabled && icon == other.icon && lang == other.lang; + return id == other.id && name == other.name && url == other.url && enabled == other.enabled && icon == other.icon + && lang == other.lang; } }; From 002b57b9e9c53222d14e1c2d7537a907c7eb74f8 Mon Sep 17 00:00:00 2001 From: Xu Jiyong Date: Thu, 25 Jan 2024 08:34:28 +0800 Subject: [PATCH 4/5] fix: Should have been 'https' for the wikipedia queries. --- src/config.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/config.cc b/src/config.cc index 922f55534..47c7dbd9b 100644 --- a/src/config.cc +++ b/src/config.cc @@ -356,13 +356,13 @@ MediaWikis makeDefaultMediaWikis( bool enable ) MediaWiki( "5d45232075d06e002dea72fe3e137da1", "Greek Wiktionary", "https://el.wiktionary.org/w", false, "" ) ); mw.push_back( MediaWiki( "c015d60c4949ad75b5b7069c2ff6dc2c", "traditional Chinese Wikipedia", - "http://zh.wikipedia.org/w", + "https://zh.wikipedia.org/w", false, "", "zh-hant" ) ); mw.push_back( MediaWiki( "d50828ad6e115bc9d3421b6821543108", "traditional Chinese Wiktionary", - "http://zh.wiktionary.org/w", + "https://zh.wiktionary.org/w", false, "", "zh-hant" ) ); From bdef8129c5453ca1939511d6499a94917299a38d Mon Sep 17 00:00:00 2001 From: Xu Jiyong Date: Sat, 10 Feb 2024 11:57:43 +0800 Subject: [PATCH 5/5] fix:typo traditional -> Traditional --- src/config.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/config.cc b/src/config.cc index 47c7dbd9b..c544f2931 100644 --- a/src/config.cc +++ b/src/config.cc @@ -355,13 +355,13 @@ MediaWikis makeDefaultMediaWikis( bool enable ) mw.push_back( MediaWiki( "5d45232075d06e002dea72fe3e137da1", "Greek Wiktionary", "https://el.wiktionary.org/w", false, "" ) ); mw.push_back( MediaWiki( "c015d60c4949ad75b5b7069c2ff6dc2c", - "traditional Chinese Wikipedia", + "Traditional Chinese Wikipedia", "https://zh.wikipedia.org/w", false, "", "zh-hant" ) ); mw.push_back( MediaWiki( "d50828ad6e115bc9d3421b6821543108", - "traditional Chinese Wiktionary", + "Traditional Chinese Wiktionary", "https://zh.wiktionary.org/w", false, "",