Marak / translate.js

translate text from one language to another on node.js and the browser. 30+ languages supported, simple as cake.
311 stars 60 forks source link

automatic language detection? #11

Open floating opened 13 years ago

floating commented 13 years ago

I couldn't find an example if this is implemented already, can anyone point me in the right direction?

If it's not implemented I will look into it via the translate api or perhaps there is a trigrams lib.

Marak commented 13 years ago

I think it's already implemented? It looks like I'm defaulting to EN => ES, not sure why.

https://github.com/Marak/translate.js/blob/master/lib/translate.js#L7

Try experimenting a little, maybe remove the defaults from being passed to Google and see if it auto-detects. I think the issue is that auto-detect isn't always 100% accurate and that it's better to just specify your language targets.

Either way, if you can do a little research and let me know the best plan of attack, I'd be glad to write a patch and add the auto-translate option to the library.

Please let me know what you find out, thanks!

floating commented 13 years ago

There is a call to detect language and it returns reliability/confidence levels that could be useful. It looks like the call you're doing now, with no default set, should auto-detect and return detectedSourceLanguage within the result object. Passing that in addition to text and errors would be good enough for what I'm trying to do.

Also defaulting to auto-detect instead of EN would be more useful in my opinion.

Thanks!

Marak commented 13 years ago

Do you think you could do a pull request for this? Even if it's not perfect it would greatly speed up things on my end.

I'm always looking for people to help maintain projects too... :-)