Comments (8)
Hi @LorenzoJokhan, thanks for creating the issue.
Unfortunately I haven't been able to reproduce this. The library includes this test case in the tests. Are you using a supported node version?
from deepl-node.
I am using version v16.17.1
from deepl-node.
Ik heb in de functie appendTextsAndReturnIsSingular(data, texts) wat console logs gedaan en krijg het volgende:
console.log({textsIsArray:Array.isArray(texts)});
console.log({arrayToTranslate:texts});
for (const key in texts) {
console.log(key);
}
wat dit geeft
{ textsIsArray: true }
{ arrayToTranslate: [ 'tekst', 'welkom' ] }
keys: 0, 1, insert
error: DeepLError: texts parameter must not be a non-empty string or array of non-empty strings
from deepl-node.
Thanks, but I could not reproduce this behavior either; the key "insert" does not appear. Does the texts
array come from an unusual source?
from deepl-node.
No, i am directly passing this array in the function:
translator.translateText(
['hallo', 'test'],
req.body.sourceLanguageCode, //this is nl
req.body.targetLanguageCode, // this is en-GB
)
as soon as i change the code to a for..of loop then it works on my side with response:
response: [
{ text: 'text', detectedSourceLang: 'nl' },
{ text: 'welcome', detectedSourceLang: 'nl' }
]
from deepl-node.
It seems a developer at my current project added a key to the prototype of array (which is not a good thing to do). Meaning that every array at our side will have that function as a key. This would mean however that if you choose to continue to use a for...in loop in deepl translation, then in the future when another library modifies the prototype they will also have these issues.
Array.prototype.insert = function ( index, item ) {
this.splice( index, 0, item );
};
The easiest fool-proof fix would be to change the loop to a for...of loop or standard for loop that only iterates over the elements instead of the keys (also mdn advises against using for..in for looping over elements https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Loops_and_iteration#for...in_statement)
from deepl-node.
Thank you for your reply, that explains the cause.
You are right about using for .. of
loops, we'll fix this soon.
from deepl-node.
This is fixed in v1.7.1.
from deepl-node.
Related Issues (20)
- Translation w/ glossary entries are only partially translated and include sourceLang string
- Feature Idea: Translate webpage from url HOT 1
- Wrong detection of source language HOT 2
- Ionic & Angular ReferenceError when initializing deepl.Translator HOT 2
- cause: Error: socket hang up when try to send many requests HOT 1
- Feature Request: Markdown Handling HOT 1
- The translation API returns an empty body in Cloudflare Workers. HOT 3
- downloadDocument() response is empty for PDFs HOT 1
- TypeError HOT 5
- XML tags with attributes change the order of the translation when tagHandling is XML but are OK when tagHandling is off HOT 5
- Uncaught TypeError: os.type is not a function HOT 5
- [tests] Jest may incorrectly detect open handles when running the tests
- Deepl Limitations - Timeout Errors during concurrent calls HOT 8
- SSL error using node 17+ HOT 4
- feature: translate a text to multiple Languages HOT 2
- Docs: `createGlossaryFromCsv` should be `createGlossaryWithCsv` HOT 1
- Axios proxy as URL HOT 1
- Update axios to latest version HOT 2
- 'ar' missing from CommonLanguageCode type HOT 4
- Translating HTML with English text to French adds HTML Tags and full sentence that is not in the input text HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from deepl-node.