jmj9e / translate

Just a quick experiment with translation using Google's Translation API against a gettext po file.
0 stars 1 forks source link

Unexpected token < at Object.parse (native) #1

Open teolemon opened 8 years ago

teolemon commented 8 years ago

I had a proper file with an api key. MacBook-Air:LC_MESSAGES pierreslam$ ls django.mo django.po node_modules translate.js translateApiKey.txt

`MacBook-Air:LC_MESSAGES pierreslam$ node translate django.po pt No api key file found.

undefined:1 <!DOCTYPE html> ^ SyntaxError: Unexpected token < at Object.parse (native) at IncomingMessage. (/Users/pierreslam/Desktop/locale/pt/LC_MESSAGES/translate.js:32:40) at IncomingMessage.emit (events.js:117:20) at _stream_readable.js:944:16 at process._tickCallback (node.js:442:13)`

teolemon commented 8 years ago

Hardcoding the API key, I got

undefined:1 <!DOCTYPE html> ^ SyntaxError: Unexpected token < at Object.parse (native) at IncomingMessage. (/Users/pierreslam/Desktop/locale/pt/LC_MESSAGES/translate.js:32:40) at IncomingMessage.emit (events.js:117:20) at _stream_readable.js:944:16 at process._tickCallback (node.js:442:13)

jmj9e commented 8 years ago

Greetings taolemon!

The expected input is a po file. There's a reference here on those: https://www.gnu.org/software/gettext/manual/html_node/PO-Files.html

For the api key file, I'm not sure why that didn't work, as long as the file was named translateApiKey.txt and in the same directory as the code, it should have been read. I guess I should add to the docs, hadn't expected anyone to use this. It was just a quick experiment. Although I need to use it myself again, so inspiration to doc it further.