Add default URL for Lingva translator

8394b976005d73f512b73600528c84ea65a901ef

Cohee <18619528+Cohee1207@users.noreply.github.com>

1 files changed, +11 -1Ignore whitespace
src/endpoints/translate.js+11 -1
@@ -11,6 +11,7 @@ import { jsonParser } from '../express-common.js';
1111
1212const DEEPLX_URL_DEFAULT = 'http://127.0.0.1:1188/translate';
1313const ONERING_URL_DEFAULT = 'http://127.0.0.1:4990/translate';
14+const LINGVA_DEFAULT = 'https://lingva.ml/api/v1';
1415
1516export const router = express.Router();
1617
@@ -189,7 +190,12 @@ router.post('/yandex', jsonParser, async (request, response) => {
189190
190191router.post('/lingva', jsonParser, async (request, response) => {
191192 try {
192193 const baseUrlsecretUrl = readSecret(request.user.directories, SECRET_KEYS.LINGVA_URL);
194+ const baseUrl = secretUrl || LINGVA_DEFAULT;
195+
196+ if (!secretUrl && baseUrl === ONERING_URL_DEFAULT) {
197+ console.log('Lingva URL is using default value.', LINGVA_DEFAULT);
198+ }
193199
194200 if (!baseUrl) {
195201 console.log('Lingva URL is not configured.');
@@ -307,6 +313,10 @@ router.post('/onering', jsonParser, async (request, response) => {
307313 console.log('OneRing URL is using default value.', ONERING_URL_DEFAULT);
308314 }
309315
316+ if (request.body.lang === 'pt-BR' || request.body.lang === 'pt-PT') {
317+ request.body.lang = 'pt';
318+ }
319+
310320 const text = request.body.text;
311321 const from_lang = request.body.from_lang;
312322 const to_lang = request.body.to_lang;