Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Lingua Libre support #268

Merged
merged 9 commits into from
Dec 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,5 @@ GoldenDict.xcodeproj/

# cmake files
/cmake-build-**/
/build**/
/build**/
CMakeLists.txt.user
5 changes: 3 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -467,14 +467,15 @@ set(PROJECT_SOURCES
zipfile.hh
zipsounds.cc
zipsounds.hh
)
src/dict/lingualibre.cpp src/dict/lingualibre.h)

qt_add_executable(${CMAKE_PROJECT_NAME}
MANUAL_FINALIZATION
${PROJECT_SOURCES})

target_include_directories(${CMAKE_PROJECT_NAME} PUBLIC
${PROJECT_SOURCE_DIR}/thirdparty/qtsingleapplication/src)
${PROJECT_SOURCE_DIR}/thirdparty/qtsingleapplication/src
${PROJECT_SOURCE_DIR}/src/)

if(MSVC)
add_compile_definitions(INCLUDE_LIBRARY_PATH)
Expand Down
24 changes: 24 additions & 0 deletions config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,14 @@ Class load()
}
}

QDomNode lingua = root.namedItem("lingua");

if(!lingua.isNull()){
applyBoolOption(c.lingua.enable,lingua.namedItem("enable"));
c.lingua.languageCodes = lingua.namedItem("languageCodes").toElement().text();
}


QDomNode forvo = root.namedItem( "forvo" );

if ( !forvo.isNull() )
Expand Down Expand Up @@ -1451,6 +1459,22 @@ void save( Class const & c )
romaji.appendChild( opt );
}

{
// Lingua

QDomElement lingua = dd.createElement("lingua");
root.appendChild(lingua);

QDomElement opt = dd.createElement("enable");
opt.appendChild(dd.createTextNode(c.lingua.enable?"1":"0"));
lingua.appendChild(opt);

opt = dd.createElement( "languageCodes" );
opt.appendChild( dd.createTextNode( c.lingua.languageCodes ) );
lingua.appendChild( opt );

}

{
// Forvo

Expand Down
16 changes: 16 additions & 0 deletions config.hh
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,21 @@ struct Transliteration
{}
};

struct Lingua
{
bool enable;
QString languageCodes;

bool operator == ( Lingua const & other ) const
{ return enable == other.enable &&
languageCodes == other.languageCodes;
}

bool operator != ( Lingua const & other ) const
{ return ! operator == ( other ); }

};

struct Forvo
{
bool enable;
Expand Down Expand Up @@ -675,6 +690,7 @@ struct Class
DictServers dictServers;
Hunspell hunspell;
Transliteration transliteration;
Lingua lingua;
Forvo forvo;
Programs programs;
VoiceEngines voiceEngines;
Expand Down
2 changes: 2 additions & 0 deletions editdictionaries.cc
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ bool EditDictionaries::isSourcesChanged() const
sources.getSoundDirs() != cfg.soundDirs ||
sources.getHunspell() != cfg.hunspell ||
sources.getTransliteration() != cfg.transliteration ||
sources.getLingua() != cfg.lingua ||
sources.getForvo() != cfg.forvo ||
sources.getMediaWikis() != cfg.mediawikis ||
sources.getWebSites() != cfg.webSites ||
Expand All @@ -199,6 +200,7 @@ void EditDictionaries::acceptChangedSources( bool rebuildGroups )
cfg.soundDirs = sources.getSoundDirs();
cfg.hunspell = sources.getHunspell();
cfg.transliteration = sources.getTransliteration();
cfg.lingua = sources.getLingua();
cfg.forvo = sources.getForvo();
cfg.mediawikis = sources.getMediaWikis();
cfg.webSites = sources.getWebSites();
Expand Down
11 changes: 7 additions & 4 deletions goldendict.pro
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ CONFIG( release, debug|release ) {

# DEPENDPATH += . generators
INCLUDEPATH += .
INCLUDEPATH += ./src/

QT += core \
gui \
Expand Down Expand Up @@ -220,12 +221,12 @@ mac {

!CONFIG( no_macos_universal ) {
LIBS+= -lhunspell
INCLUDEPATH = $${PWD}/maclibs/include
INCLUDEPATH += $${PWD}/maclibs/include
LIBS += -L$${PWD}/maclibs/lib -framework AppKit -framework Carbon
}
else{
PKGCONFIG += hunspell
INCLUDEPATH = /opt/homebrew/include /usr/local/include
INCLUDEPATH += /opt/homebrew/include /usr/local/include
LIBS += -L/opt/homebrew/lib -L/usr/local/lib -framework AppKit -framework Carbon
}

Expand Down Expand Up @@ -389,7 +390,8 @@ HEADERS += folding.hh \
gls.hh \
splitfile.hh \
favoritespanewidget.hh \
treeview.hh
treeview.hh \
src/dict/lingualibre.h

FORMS += groups.ui \
dictgroupwidget.ui \
Expand Down Expand Up @@ -526,7 +528,8 @@ SOURCES += folding.cc \
gls.cc \
splitfile.cc \
favoritespanewidget.cc \
treeview.cc
treeview.cc \
src/dict/lingualibre.cpp

win32 {
FORMS += texttospeechsource.ui
Expand Down
5 changes: 5 additions & 0 deletions icons/lingualibre.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions icons/readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,6 @@ sources.png https://icons.iconarchive.com/icons/oxygen-icons.org/oxygen/128/Apps
book.svg https://github.com/johnfactotum/foliate


lingualibre.svg https://en.m.wikipedia.org/wiki/File:Lingualibre-logo-no-text.svg


10 changes: 10 additions & 0 deletions loaddictionaries.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "dictserver.hh"
#include "slob.hh"
#include "gls.hh"
#include "dict/lingualibre.h"

#ifndef NO_EPWING_SUPPORT
#include "epwing.hh"
Expand Down Expand Up @@ -351,6 +352,15 @@ void loadDictionaries( QWidget * parent, bool showInitially,
dictionaries.insert( dictionaries.end(), dicts.begin(), dicts.end() );
}

//// Lingua Libre

{
vector< sptr< Dictionary::Class > > dicts =
Lingua::makeDictionaries( loadDicts, cfg.lingua, dictNetMgr );

dictionaries.insert( dictionaries.end(), dicts.begin(), dicts.end() );
}

//// Programs
{
vector< sptr< Dictionary::Class > > dicts =
Expand Down
1 change: 1 addition & 0 deletions resources.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<file>article-style-st-lingvo.css</file>
<file>icons/icon_dsl_native.png</file>
<file>icons/forvo.png</file>
<file>icons/lingualibre.svg</file>
<file>CREDITS.txt</file>
<file>icons/highlighter.png</file>
<file>icons/macicon.png</file>
Expand Down
16 changes: 16 additions & 0 deletions sources.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ Sources::Sources( QWidget * parent, Config::Class const & cfg):

Config::Hunspell const & hunspell = cfg.hunspell;
Config::Transliteration const & trs = cfg.transliteration;

Config::Lingua const & lingua = cfg.lingua;
Config::Forvo const & forvo = cfg.forvo;

// TODO: will programTypeEditorCreator and itemEditorFactory be destroyed by
Expand Down Expand Up @@ -114,6 +116,9 @@ Sources::Sources( QWidget * parent, Config::Class const & cfg):
ui.enableHiragana->setChecked( trs.romaji.enableHiragana );
ui.enableKatakana->setChecked( trs.romaji.enableKatakana );

ui.linguaEnabled->setChecked(lingua.enable);
ui.linguaLangCode->setText(lingua.languageCodes);

ui.forvoEnabled->setChecked( forvo.enable );
ui.forvoApiKey->setText( forvo.apiKey );
ui.forvoLanguageCodes->setText( forvo.languageCodes );
Expand Down Expand Up @@ -376,6 +381,17 @@ Config::Transliteration Sources::getTransliteration() const
return tr;
}

Config::Lingua Sources::getLingua() const
{
Config::Lingua lingua;

lingua.enable = ui.linguaEnabled->isChecked();
lingua.languageCodes = ui.linguaLangCode -> text();

return lingua;
}


Config::Forvo Sources::getForvo() const
{
Config::Forvo forvo;
Expand Down
2 changes: 2 additions & 0 deletions sources.hh
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,8 @@ public:

Config::Transliteration getTransliteration() const;

Config::Lingua getLingua() const;

Config::Forvo getForvo() const;

signals:
Expand Down
74 changes: 71 additions & 3 deletions sources.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@
<rect>
<x>0</x>
<y>0</y>
<width>929</width>
<width>1010</width>
<height>336</height>
</rect>
</property>
<property name="windowTitle">
<string notr="true">Sources</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_5">
<layout class="QVBoxLayout" name="verticalLayout_9">
<item>
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
<number>0</number>
<number>7</number>
</property>
<property name="iconSize">
<size>
Expand Down Expand Up @@ -456,6 +456,74 @@ of the appropriate groups to use them.</string>
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_lingua">
<attribute name="icon">
<iconset resource="resources.qrc">
<normaloff>:/icons/lingualibre.svg</normaloff>:/icons/lingualibre.svg</iconset>
</attribute>
<attribute name="title">
<string>Lingua Libre</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_5">
<item>
<widget class="QLabel" name="label_17">
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Prouncations provied by &lt;a href=&quot;https://lingualibre.org&quot;&gt;&lt;span style=&quot; text-decoration: underline; color:#2980b9;&quot;&gt;Lingua Libre&lt;/span&gt;&lt;/a&gt;, a collaborative linguistic media library of Wikimedia France. &lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="openExternalLinks">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QGroupBox" name="linguaEnabled">
<property name="title">
<string>Enable Lingua Libre</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<layout class="QFormLayout" name="formLayout_2">
<item row="0" column="0">
<widget class="QLabel" name="label_18">
<property name="text">
<string>ISO 639-3 language code</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="linguaLangCode"/>
</item>
<item row="1" column="1">
<widget class="QLabel" name="label_19">
<property name="text">
<string>Examples: &amp;quot;eng&amp;quot; for Enligh, &amp;quot;fra&amp;quot; for French) &lt;br&gt;

Full list of availiable languages can be found &lt;a href=&quot;https://lingualibre.org/wiki/LinguaLibre:Stats/Languages&quot;&gt; here &lt;/a&gt;</string>
</property>
<property name="openExternalLinks">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer_4">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_5">
<attribute name="icon">
<iconset resource="resources.qrc">
Expand Down
Loading