Skip to content
This repository was archived by the owner on Jul 4, 2024. It is now read-only.

Commit e2e22f8

Browse files
authored
Make setEngineUrl method required for LibreTranslate and Lingva to work
1 parent 2712856 commit e2e22f8

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

src/qonlinetranslator.cpp

100755100644
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1890,6 +1890,11 @@ void QOnlineTranslator::buildLibreStateMachine()
18901890

18911891
void QOnlineTranslator::buildLibreDetectStateMachine()
18921892
{
1893+
Q_ASSERT_X(
1894+
!m_libreUrl.isEmpty(),
1895+
"buildLibreDetectStateMachine",
1896+
"The engine requires a URL, but it was not specified");
1897+
18931898
// States
18941899
auto *detectState = new QState(m_stateMachine);
18951900
auto *finalState = new QFinalState(m_stateMachine);
@@ -1918,6 +1923,11 @@ void QOnlineTranslator::buildLingvaStateMachine()
19181923

19191924
void QOnlineTranslator::buildLingvaDetectStateMachine()
19201925
{
1926+
Q_ASSERT_X(
1927+
!m_lingvaUrl.isEmpty(),
1928+
"buildLingvaDetectStateMachine",
1929+
"The engine requires a URL, but it was not specified");
1930+
19211931
// States
19221932
auto *detectState = new QState(m_stateMachine);
19231933
auto *finalState = new QFinalState(m_stateMachine);

src/qonlinetranslator.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,8 @@ class QOnlineTranslator : public QObject
430430
/**
431431
* @brief Set the URL engine
432432
*
433-
* Affects only LibreTranslate and Lingva.
433+
* Only affects LibreTranslate and Lingva because these engines have multiple instances.
434+
* You need to call this function to specify the URL of an instance for them.
434435
*
435436
* @param engine engine
436437
* @param url engine url
@@ -622,11 +623,9 @@ private slots:
622623
QString m_errorString;
623624

624625
// Self-hosted engines settings
625-
// LibreTranslate
626-
QByteArray m_libreApiKey; // Doesn't require key for free instance
627-
QString m_libreUrl = QStringLiteral("https://translate.argosopentech.com"); // One of the free instance
628-
// Lingva
629-
QString m_lingvaUrl = QStringLiteral("https://lingva.ml");
626+
QByteArray m_libreApiKey; // Can be empty, since free instances ignores api_key param
627+
QString m_libreUrl;
628+
QString m_lingvaUrl;
630629

631630
QMap<QString, QVector<QOption>> m_translationOptions;
632631
QMap<QString, QVector<QExample>> m_examples;

0 commit comments

Comments
 (0)